We can use three methods to apply styles to an object (such as div, span, table).
1: Use # to define the style and use the id to apply the style to the object.
Example:
Id 用Id来给对象应用样式
2: Use . to define the style, and use class to apply the style to the object.
Example:
Id 用class来给对象应用样式
3: Do not define a style, use style directly to apply styles to objects.
Example:
Id 用style来给对象应用样式
The effect of using these three methods is the same, but what we need to pay attention to is the priority issue between these three methods.
What happens if we use the above three methods to define styles for an object at the same time?
For example, we first define a #STYLE { font-size:12px; } and then define a .STYLE { font-size:14px; } and finally use style="font-size:16px;" on the object. The code is as follows:
Id 用三种方式同时来给对象应用样式
In this case, the browser will apply styles to the object according to the priority of the three methods, namely style>id>class. In the above example, the text in the div will be displayed at 16px size.
The above is the detailed content of Example analysis of three style methods (id, class, style) in css. For more information, please follow other related articles on the PHP Chinese website!