Home >Web Front-end >CSS Tutorial >Introduction to id selector and class selector in css
id selector
The id selector can specify a specific style for HTML elements marked with a specific id.
The HTML element uses the id attribute to set the id selector, and the id selector in CSS is defined with "#".
For example:
#para1 { text-align:center; color:red; }
Note: Do not start the ID attribute with a number. IDs starting with numbers will not work in Mozilla/Firefox browsers.
class selector
class selector is used to describe the style of a group of elements. The class selector is different from the id selector. Class can be used in multiple used in elements.
class selector is represented by the class attribute in HTML, and in CSS, the class selector is displayed with a dot "."
For example:
In the following example, all HTML elements with the center class are centered.
.center {text-align:center;}
You can also specify specific HTML elements using classes.
For example:
In the following example, all p elements use class="center" to center the text of the element.
p.center {text-align:center;}
Recommended tutorial: CSS basic tutorial
The above is the detailed content of Introduction to id selector and class selector in css. For more information, please follow other related articles on the PHP Chinese website!