Example analysis of three style methods (id, class, style) in css

黄舟
Release: 2017-07-20 09:17:45
Original
2110 people have browsed it

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来给对象应用样式
Copy after login

2: Use . to define the style, and use class to apply the style to the object.
Example:

    Id  
  
用class来给对象应用样式
Copy after login

3: Do not define a style, use style directly to apply styles to objects.
Example:

    Id 
  
用style来给对象应用样式
Copy after login

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  
  
用三种方式同时来给对象应用样式
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Chrome doesn't apply padding to select options Select option padding not working in Chrome