Home > Article > Web Front-end > How to define CSS id selector
CSS id selector
The id selector can specify a specific style for HTML elements marked with a specific id .
id selector is defined with "#". (Recommended learning: CSS Introduction Tutorial)
The following two id selectors, the first one can define the color of the element as red, and the second one can define the color of the element as Green:
#red {color:red;} #green {color:green;}
In the following HTML code, the p element whose id attribute is red is displayed in red, and the p element whose id attribute is green is displayed in green.
<p id="red">这个段落是红色。</p> <p id="green">这个段落是绿色。</p>
Note: The id attribute can only appear once in each HTML document.
Individual selector
The id selector can function independently even if it is not used to create a derived selector:
#sidebar { border: 1px dotted #000; padding: 10px; }
According to According to this rule, the element with the id of sidebar will have a pixel-wide black dotted border, and there will be 10 pixels of padding around it.
Older versions of Windows/IE browsers may ignore this rule unless you specifically define the element to which this selector belongs:
div#sidebar { border: 1px dotted #000; padding: 10px; }
The above is the detailed content of How to define CSS id selector. For more information, please follow other related articles on the PHP Chinese website!