This is an article about css hack. The css hack mentioned in this article is aimed at the HACK of the attributes in the class and id, and the ordering is required. Today I want to talk about CSS HACK for class and id.
The code is as follows: |
Copy code |
. Test {/* FF */ Height: 20px; Background-color: orange; } * + Html. test {/* IE7 */ Height: 20px; Background-color: blue; } * Html. test {/* IE6 */ Height: 20px; Background-color: black; } |
Through the CSS code above, we can see that FF is the most obedient browser. To use HACK in IE6 and IE7, you must add the class tag html in front. This is a good memory. IE6 adds * html, while IE7 adds * + html, which implies adding a version. The advantage of css hack for class and id is that it does not take into account the order before and after, and is easy for management and acceptance by other people. It can also be used to control versions similar to JS browsers. The disadvantage is that a large amount of code is generated! Okay. Let's talk about this first.
After reading the above content, you can click the following effects to see the effects in different browsers. Orange indicates FF, blue indicates IE7, and black indicates IE6. You can test it on your own.
Webpage Tutorial network
The code is as follows: |
Copy code |
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/> <Title> CSS hack </title> <Style type = "text/css"> *{ Margin: 0; Padding: 0; } . Test {/* FF */ Height: 20px; Background-color: orange; } * + Html. test {/* IE7 */ Height: 20px; Background-color: blue; } * Html. test {/* IE6 */ Height: 20px; Background-color: black; } </Style> </Head> <Div class = "test"> </div> <Body> </Body> </Html> |