CSS class selector and ID selector

Source: Internet
Author: User
In CSS, the class selector is displayed with a dot number:

. Center {Text-align:center}
In the example above, all HTML elements that have the center class are centered.

In the following HTML code, both the H1 and P elements have the center class. This means that both will adhere to the rules in the. Center selector.

<H1 class= "center" > This heading would be a center-aligned
*****************************
ID Selector
The ID selector can specify a specific style for an HTML element that is labeled with a specific ID. The ID selector is defined as "#". The following two ID selectors, the first one can define the color of the element to be red, the second defines the color of the element as green:
#red {color:red;} #green {color:green;}
In the following HTML code, the P element with the ID property of red is shown in red, and the P element with the id attribute green is shown in the blue.
<p id= "Red" > This paragraph is red. </p> <p id= "Green" > This paragraph is greenish. </p>
Note: The id attribute can only appear once in each HTML document. Want to know why, see XHTML: Site refactoring.

  • 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.