English 中文(简体)
社会保障局并不超越继承价值
原标题:CSS does not override inherited values

I have an Html that contains something like: (Multiple divs within div A).

<div class="a">
    <div class="b"></div>
</div>

我想:

.a div {
    border: solid;
    border-width: thin;
}

.b {
    border: none;
    border-width: 0px;
    border-collapse: collapse;
}

For some reason b s values will not override a. however, if i just write a rather than "a .div" i won t get the behavior expected for the other divs inside a.

The only way i got this to work is using "important!" (ie "border: none!important";) but that seems less than elegant.

热爱对那里正在发生的一切的想法。

Ehud。

最佳回答

.a div has a higher specificity than .b.
If you want the css for .b to override the .a one, give it a higher specificity still, for instance .a div.b.

(你可以使用<代码>! 进口, 是,但此处不建议这样做)

问题回答

你的挑选者是错误的。

a. div {

Write

div.a {

(select any div with a class of "a")

b {

(这实际上将试图打上所有b 内容)

用途

.b {

(这是指选择“b”类定义的任何东西)

<>strong>EDIT(回应)

选择与“a”类分离的四分之三,使用以下选择:

div.a div 

<>Specificity s分由中央支助事务汇编者计算,宣言中的最高分数用于修改内容。

核心一般按这一顺序计算:

inline   id-element   class-element   no.-of-elements
  $          $             $                $

($) -> 1 if the respective type of specificity exists in code
($) -> 0 if the respective type of specificity doesn t exists in code

So here
for .a div score will be 0012
for .b score will be 0011
Clearly first one wins so it gets to modify the content even though .b tries to override .a div

(OR)

you can use !important in the declaration to finalize that declaration





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签