The importance of getting started easily with HTML+CSS
When we are making web page code, there are some special situations where we need to set the highest weight for certain styles. What should we do? At this time we can use !important to solve it.
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>!important</title> <style type="text/css"> p{ color:red!important; } p.first{ color:green; } </style> </head> <body> <h1>勇氣</h1> <p class="first">三年級(jí)時(shí),我還是一個(gè)<span>膽小如鼠</span>的小女孩,上課從來(lái)不敢回答老師提出的問(wèn)題, 生怕回答錯(cuò)了老師會(huì)批評(píng)我。就一直沒(méi)有這個(gè)勇氣來(lái)回答老師提出的問(wèn)題。學(xué)校舉辦的活動(dòng)我也沒(méi)勇氣參加。</p> <p id="second">到了三年級(jí)下學(xué)期時(shí),我們班上了一節(jié)公開課,老師提出了一個(gè)很 <span class="first">簡(jiǎn)單</span> 的問(wèn)題,班里很多同學(xué)都舉手了,甚至成績(jī)比我差很多的, 也舉手了,還說(shuō)著:"我來(lái),我來(lái)。"我環(huán)顧了四周,就我沒(méi)有舉手。 </p> </body> </html>
At this time, the text in the p paragraph will be displayed in red.
Note: !important should be written in front of the semicolon
Note here that when the web page creator does not set the css style, the browser will display the web page according to its own set of styles. And users can also set their own custom styles in the browser. For example, some users are used to setting the font size to a larger size so that they can view the text of the web page more clearly. At this time, please note that the style priority is: browser default style < web page creator style < style set by the user, but remember that the !important priority style is an exception and has a higher weight than the style set by the user.