Everybody read it. A summary of the differences between class-class and identity-ID selectors in CSS styles-experience Exchange

Source: Internet
Author: User
You can define your own selectors with class selector classes and identity selector IDs.

The advantage of this is that depending on the class or ID, you can perform the same HTML elements differently.

In CSS, the class selector precedes a half-width period (.), and the ID is preceded by a half-width English pound sign (#).

Looks like this:

#top {background-color: #ccc; padding:1em}. intro {color:red; font-weight:bold;}
HTML joins the CSS with the attribute ID and class. Like this:

Chocolate Curry

This is my recipe-making curry purely with chocolate

Mmm mm Mmmmm



The difference between ID and class is that the ID is used on the unique element, and the class is used on more than one element.

You can also apply a selector to a specified HTML element, placing the HTML selector in front of it, so that P.jam {whatever} is applied to the paragraph with the class "jam".


An ID name is usually uniquely defined on a page, so defining a CSS in a page usually suggests a class, so you can reuse your CSS. and leave the ID to the JavaScript that most needs to use HTML elements, etc.
  • 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.