CSS优先,inlne还是类? [英] CSS which takes precedence, inlne or the class?
问题描述
我的网站有一个样式表在标题中定义为style.css与选择器:
My website has a stylesheet defined in the header as style.css with a selector:
.myClass {background:#000;}
现在我的div看起来像:
Now my div looks like:
<div class="myClass" style="background:#fff;"> </div>
哪一个有优先级,内联或类?
Which one has priority, the inline or the class?
推荐答案
一般来说,我们可以说,所有的样式将通过以下规则级联 ,其中第四个具有最高优先级:
Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority:
1.浏览器默认值
2.外部样式表
3.内部样式表section)
4.内联样式(在HTML元素内)
1.Browser default 2. External style sheet 3. Internal style sheet (in the head section) 4.Inline style (inside an HTML element)
源: w3schools
W3schools解释了很多关于CSS的内容,并且展示了你可以用CSS做的大多数事情的例子。如果您对某些问题有任何疑问,总是一个好资源。
W3schools explains a lot about CSS and also goes through and shows examples of most things you can do with CSS. Always a good resource if you have questions about something.
这篇关于CSS优先,inlne还是类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!