If we want to set CSS styles in HTML elements, then we need to set the "id" and "class" selectors in the element.
(Recommended tutorial: CSS tutorial)
Let’s talk about the id selector and class selector respectively.
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 "#".
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 elements. .
The class selector is represented by the class attribute in HTML. In CSS, the class selector is displayed with a dot ".":
Example:
.center {text-align:center;}
Note: The first character of the class name cannot be a number! It won't work in Mozilla or Firefox.
The above is the detailed content of What is the way to set css style in html element. For more information, please follow other related articles on the PHP Chinese website!