Home > Web Front-end > Front-end Q&A > What does id mean in css?

What does id mean in css?

藏色散人
Release: 2020-12-22 10:02:48
Original
4188 people have browsed it

id represents the ID selector in CSS. The ID selector allows the style to be specified in a manner independent of the document element; the HTML element uses the id attribute to set the id selector, while the id selector in CSS Devices are defined with "#", also known as checkerboard numbers or pound signs.

What does id mean in css?

Recommended: "css video tutorial"

CSS ID Selector

In some ways, ID selectors are similar to class selectors, but there are some important differences.

Syntax

The HTML element uses the id attribute to set the id selector, and the id selector in CSS is defined with "#" - also known as the checkerboard number or pound sign .

Please see the following rules:

*#intro {font-weight:bold;}
Copy after login

Like class selectors, wildcard selectors can be ignored in ID selectors. The previous example could also be written as:

#intro {font-weight:bold;}
Copy after login

The effect of this selector would be the same.

The second difference is that the ID selector does not refer to the value of the class attribute. There is no doubt that it refers to the value in the id attribute.

Usage:

html
<div class="to">
    <p id="dog">指定具有id元素的样式</p>
</div>
css
 #dog{
        background-color: aqua;
    }
Copy after login

Case Sensitive

Please note that class selectors and ID selectors may be case sensitive. This depends on the language of the document. HTML and XHTML define class and ID values ​​as case-sensitive, so the case of class and ID values ​​must match the corresponding values ​​in the document.

Therefore, for the following CSS and HTML, the element will not be made bold:

#intro {font-weight:bold;}
<p id="Intro">This is a paragraph of introduction.</p>
Copy after login

The selector will not match the above element due to the different case of the letter i.

The above is the detailed content of What does id mean in css?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template