CSS cascade
Let's think about a question: What if there can be multiple css styles for the same element in the html file and these multiple css styles have the same weight value? Well, the cascading in this section helps you solve this problem.
Cascading means that there can be multiple css styles for the same element in the html file. When there are styles with the same weight, it will be determined based on the order of these css styles. The last css style will be applied.
Such as the following code:
p{color:red;} p{color:green;} <p class="first">三年级时,我还是一个<span>胆小如鼠</span>的小女孩。</p>
Finally, the text in p will be set to green. This cascading is easy to understand. It is understood that the later styles will overwrite the previous styles.
So the previous CSS style priority is not difficult to understand:
Inline style sheet (inside the tag) > Embedded style sheet (in the current file) > External style Table (in external file) .
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>层叠</title> <style type="text/css"> p{color:red;} p{color:green;} p{color:pink;} .first{ color:purple;} #second{ color:orange;} </style> </head> <body> <h1>勇气</h1> <p class="first">三年级时,我还是一个<span>胆小如鼠</span>的小女孩,上课从来不敢回答老师提出的问题,生怕回答错了老师会批评我。就一直没有这个勇气来回答老师提出的问题。学校举办的活动我也没勇气参加。</p> <p id="second">到了三年级下学期时,我们班上了一节公开课,老师提出了一个很<span>简单</span>的问题,班里很多同学都举手了,甚至成绩比我差很多的,也举手了,还说着:"我来,我来。"我环顾了四周,就我没有举手。</p> </body> </html>