CSS advanced syntax

巴扎黑
Release: 2017-03-18 13:43:39
Original
1363 people have browsed it

[Introduction] Grouping of selectors You can group selectors so that grouped selectors can share the same statement. Use commas to separate selectors that need to be grouped. In the example below, we have grouped all heading elements. All title elements are green. h1,h2,h3,h4,h5

Group of selectors


You can group selectors so that the grouped selectors are The same statement can be shared. Use commas to separate selectors that need to be grouped. In the example below, we have grouped all heading elements. All title elements are green.

h1,h2,h3,h4,h5,h6 {
color: green;
}

Inheritance and its problems


According to CSS, child elements inherit properties from their parent elements. But it doesn't always work this way. Take a look at the following rule:

body {
font-family: Verdana, sans-serif;
}

According to the above rule, the body element of the site will use Verdana font (if the font is present on the visitor's system).

Through CSS inheritance, child elements will inherit the attributes owned by the highest-level element (in this case, body) (these child elements such as p, td, ul, ol, ul, li, dl, dt, and dd). No additional rules are needed, all child elements of the body should display the Verdana font, as well as the child elements of the child element. And in most modern browsers, this is indeed the case.

But in the bloody days of the browser wars, this might not have happened, when support for standards was not a priority for enterprises. For example, Netscape 4 does not support inheritance and not only ignores inheritance, but also ignores rules that apply to the body element. There is still a related issue in IE/Windows up to IE6 where font styles in tables will be ignored. What should we do?


Be Kind to Netscape 4


Luckily, you can do this by using a redundancy we call "Be Kind to Netscape 4" Rules to deal with legacy browsers not being able to understand inheritance.

body {
font-family: Verdana, sans-serif;
}

p, td, ul, ol, li, dl, dt, dd {
font-family: Verdana, sans-serif;
}

4.0 Browsers don’t understand inheritance, but they do understand group selectors. Although this will waste some users' bandwidth, it must be done if you need to support Netscape 4 users.


Is inheritance a curse?


What if you don't want the "Verdana, sans-serif" font to be inherited by all child elements? Let's say you want the font of your paragraph to be Times. no problem. Create a special rule for p so that it gets rid of the parent element's rule:

body {
font-family: Verdana, sans-serif;
}

td , ul, ol, ul, li, dl, dt, dd {
font-family: Verdana, sans-serif;
}

p {
font-family: Times, " Times New Roman", serif;
}

The above is the detailed content of CSS advanced syntax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!