An example of a CSS element with both an ID selector and a class selector

Source: Internet
Author: User

An element can have both an ID selector and a class selector, but only one ID selector, and the ID selector has a precedence greater than the class selector.

Cases:

HTML file Contents:



<title> an element can have both an ID selector and a class selector </title>
<link rel= "stylesheet" type= "Text/css" href= "Test.css"/>
<body>
<div class= "CLS1" id= "ID1" ><span> Thank you for visiting <a href= "http://www.bianceng.cn" >www.bianceng.cn</a ></span>, hope to help you! </div>
</body>

Contents of Test.css File:

/* An element can have both an ID selector and a class selector.
#id1 {
Background-color:silver;
font-size:40px;
Color:black;
}
#id1 span{
color:red;
Font-style:italic;
}
#id1 span a{
Color:green;
Text-decoration:none;
}
. cls1{
color:red;
Font-style:italic;
}

The effect of the following figure:

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/web/Css/

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.