Css id selector (3) and cssid Selector

Source: Internet
Author: User

Css id selector (3) and cssid Selector
I. ID Selector

The ID selector uses the "#" prefix identifier for identification, followed by the ID name of the specified element.

For example

#box{ width:100px; height:100px;}

The element ID name is unique and can only correspond to a specific element in the document. In HTML, the tag used to build the overall framework should define the ID attribute, because this object is generally unique on the page, fixed, and will not be repeated, such as the Logo inclusion box, navigation bar, subject inclusion box, and copyright area.

Ii. Set the page layout by ID
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
@charset "utf-8";/* CSS Document */#header{    margin:0 auto;    width:960px;    height:210px;    border:solid 1px #000000;}#logo{    width:100px;    height:100px;    border:solid 1px #000000;    float:left;}#banner{    margin-left:30px;    float:left;    width:800px;    height:100px;    border:solid 1px #000000;}#nav{    clear:both;    margin:0 auto;    width:800px;    height:100px;    border:solid 1px #000000;}
Iii. Internal class attribute of external ID
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
@ Charset "UTF-8";/* CSS Document * // * parent style */# father {width: 500px; height: 500px; border: solid 2px blue; margin: 5px;}/* set the tag div Mode Under the parent style through the parent style */# father div {width: 100px; height: 100px; border: solid 1px red; padding: 10px; margin: 10px; background-color: # 0000FF;}/* set the class under the parent style through the parent style */# father. child1 {width: 100px; height: 100px; margin: 20px; padding: 10px; border: solid 5px # FF00FF; background-color: #66FF00 ;} /* set the class under the parent style through the parent style */# father. child2 {width: 100px; height: 100px; margin: 10px; padding: 10px; border: solid 5px #00FF00; background-color: # FF0000 ;} /* setting the class style directly does not work because the above # father div has already been set. The class selector priority here is smaller than the label selector */. child3 {width: 100px; height: 100px; margin: 10px; padding: 10px; border: solid 10px # 0000FF; background-color: # FF00FF ;}

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.