CSS intermediate tutorial class and id selector

Source: Internet
Author: User
Tags html tags

In the CSS Elementary tutorial, we only consider the HTML selector-in the form of HTML tags.
Of course, you can use the class selector and the identifier selector id to define your own selector.
The benefit of doing so is that depending on the class or id, you can behave the same HTML element differently.
In CSS, the class selector is prior to a half-width English period (.), and the id is prior to the half-width English well number.
It looks like this:

The code is as follows: Copy code
# Top {
Background-color: # ccc;
Padding: 1em

. Intro {
Color: red;
Font-weight: bold;

The link between HTML and CSS uses the property id and class. Like this:

The code is as follows: Copy code
<Div id = "top">
<H1> Chocolate curry <P class = "intro"> This is my recipe for making curry purely with chocolate </p>
<P class = "intro"> Mmm mmmmm </p>
</Div>

The difference between id and class is that id is used on unique elements, while class is used on more than one element.
You can also apply a selection character to a specified HTML element and place the HTML selection character in front of it. Therefore, p. jam {whatever} will be applied to the section with the class "jam.

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.