简体   繁体   English

CSS样式-覆盖背景如何工作?

[英]CSS Styles - how does overriding background work?

There's a pile of questions with related sounding titles, but I didn't see my answer for this question in case anyone is checking (feel free to leave a reference though!). 有一堆与相关的发音标题相关的问题,但是如果有人检查(我可以随意留下参考!),我没有看到这个问题的答案。

This is more out of inexperience than anything... but if I have a global stylesheet that sets the CSS properties of a class div.rowpic , and then I do this: 这比没有经验更重要……但是,如果我有一个全局样式表来设置div.rowpic类的CSS属性,然后执行此操作:

<div class="rowpic" style="background-image: url('whatever.jpg');"> ... </div>

Can I reliably expect browsers to use the full CSS specification of div.rowpic but replace its background image with the style I explicitly stated in this div tag? 我能否可靠地期望浏览器使用div.rowpic的完整CSS规范,但用我在此div标签中明确声明的样式替换其背景图像?

Yes, that's what should happen. 是的,那应该发生。

Style in the element overrides the definition of the style in the declared CSS('s). 元素中的样式会覆盖声明的CSS中样式的定义。

Each property of the styling is applied independently from the others, so even if you import another CSS after that one that has the same class but only redefines some of the selectors, you still get the remaining ones applied from the first CSS. 样式的每个属性均独立于其他属性应用,因此,即使您在具有相同类但又重新定义了某些选择器的那个属性之后导入另一个CSS,您仍然会从第一个CSS应用其余的选择器。

Of course. 当然。 In this case, the background image will be replaced since inline styling rule is more important of css styling rules. 在这种情况下,将替换背景图像,因为内联样式规则在css样式规则中更为重要。

Please read this article about CSS specificity: http://css-tricks.com/855-specifics-on-css-specificity/ 请阅读有关CSS特殊性的文章: http : //css-tricks.com/855-specifics-on-css-specificity/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM