Select element by Id
~10 mins
Select element by Id
- This trick helps you select an element using the ID as a value for an attribute selector to avoid the high specificity of
the ID selector.
<div id="element">...</div>
#element { ... } /* High specificity will override many selectors */
<div id="exampleID">
<p>Example</p>
</div>
#exampleID {
width: 20px;
}
-
Note: The HTML specs do not allow multiple elements with the same ID
-
Reference: Section 4.12