Understanding of CSS selector weight (personal test)

Understanding of CSS selector weight (personal test)


Copy code
The code is as follows:

<style type="text/css">
div.ui_infor p {font-size: 16px;}
.ui_infor p {font-size: 14px;}
</style>


Copy code
The code is as follows:

<div class="ui_infor">
<p>test of css</p>
</div>

In the above example, the final display effect is font-size: 16px, not the following font-size: 14px;
This combination of selectors has a quick method to judge:
0,0,0,0
The first digit represents the style written on the label, such as

Copy code
The code is as follows:

<p style="font-size: 14px;"></p>

The second digit represents the id selector, such as #demo {}
The third digit represents: class name (.demo {}) or pseudo class (:hover) or attribute selector [rel="xx"]
The fourth digit represents: tag selector p {}
Now let’s practice with the first example:

Copy code
The code is as follows:

div.ui_infor p {font-size: 16px;}

Its weights are: 0,0,1,2

Copy code
The code is as follows:

.ui_infor p {font-size: 14px;}

Its weights are: 0,0,1,1
Result: 0,0,1,2 > 0,0,1,1, so font-size: 16px is displayed;
Supplement: !important has the highest weight, so there is no need to judge, but it will cause a bug in IE-6 browser.
example:

Copy code
The code is as follows:

p {font-size: 18px !important;font-size: 12px;}

In IE-6 browser, font-size: 12px is displayed. Some information on the Internet says that IE-6 does not support !important, which is actually wrong.
Let’s look at an example:

Copy code
The code is as follows:

p {font-size: 18px !important;}
p {font-size: 12px;}

In IE-6, font-size: 18px is displayed, which means that IE-6 supports !important, but the performance is a bit weird. The weird thing is that the !important attribute is overwritten by the latter style with the same name.
For example, in the example p {font-size: 18px !important;font-size: 12px;}, font-size: 12px overrides font-size: 18px !important.
Using this quirk, you can implement "min-height" in IE-6 without using CSS_hack

Copy code
The code is as follows:

p { min-height: 50px; height:auto !important; height:50px;}

<<:  Introduction to the process of extending the boot partition in Kylin 4.0.2 (Ubuntu)

>>:  MySQL tutorial thoroughly understands stored procedures

Recommend

Detailed explanation of new relational database features in MySQL 8.0

Preface The latest version of MySQL 8.0 is 8.0.4 ...

Scoring rules of YSlow, a webpage scoring plugin developed by Yahoo

YSlow is a page scoring plug-in developed by Yaho...

MySql grouping and randomly getting one piece of data from each group

Idea: Just sort randomly first and then group. 1....

Explanation of the new feature of Hadoop 2.X, the recycle bin function

By turning on the Recycle Bin function, you can r...

Implementation of MySQL scheduled database backup (full database backup)

Table of contents 1. MySQL data backup 1.1, mysql...

How to delete folders, files, and decompress commands on Linux servers

1. Delete folders Example: rm -rf /usr/java The /...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...

Detailed explanation of the execution process of mysql update statement

There was an article about the execution process ...

Analysis of Alibaba Cloud CentOS7 server nginx configuration and FAQs

Preface: This article refers to jackyzm's blo...

How to add a pop-up bottom action button for element-ui's Select and Cascader

As shown in the figure below, it is a common desi...

A brief discussion on MySQL count of rows

We are all familiar with the MySQL count() functi...

The difference between Input's size and maxlength attributes

I recently used the input size and maxlength attri...

How to set up swap partition SWAP in Linux 7.7

The Swap partition of the Linux system, that is, ...