Css hack for class and id

Source: Internet
Author: User

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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.