How do HTML elements determine whether to use an ID or a class selector? Example

Source: Internet
Author: User
When we are building the website, we must design the content of the website in style. So what do we need to do to set CSS styles in HTML elements? Here we need to set the ID and class selector in the HTML element. That some novice friends may ask, CSS class how to use? Does the DIV tag use ID or class?

This article will give you a description of the CSS class selector ID and class usage and differences. It is hoped that the description of the ID and class-readable points will help.

First, the CSS class selector ID code uses the following example:

<! DOCTYPE html>

Effects such as:

Second, the CSS class selector class Code use example is as follows:

<! DOCTYPE html>

Effects such as:

Third, the combination of ID and class is the above two methods together.

It is important to note that:

ID plus prefix "#"; ID a page can only be used once;

The ID selector can specify a specific style for an HTML element that is labeled with a specific ID.

Class can be referenced multiple times with the "." Class.

The class selector is used to describe the style of a set of elements, which differs from the ID selector, and class can be used in multiple elements.

So through this article about CSS. Class#id The introduction of these two selectors, I hope the novice in the tangle with the class or ID when it is helpful.


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.