Cancel a CSS declaration

后端 未结 8 976
礼貌的吻别
礼貌的吻别 2021-02-07 08:47

Is it possible to have a CSS rule which basically \"undoes\" a prior rule?

An example:

some text more text ot
相关标签:
8条回答
  • 2021-02-07 09:25

    If you can change your html you could try

    <li><span>This text should be BLUE</span>
        <ul>
            <li>Same as outside the UL</li>
            <li>Same as outside the UL</li>
        </ul>
    </li>
    

    and the style

    li span{
        color: blue;
    }
    

    EDIT another way to accomplish this without the extra span tag:

    If we assume that we have a style class (or any other selector) that defines to parent of the outer ul. We can modify the css like this:

    .parentStyle,
    .parentStyle li li{
         color:red;
    }
    li{
         color:blue;
    }
    
    0 讨论(0)
  • 2021-02-07 09:27

    Rather than trying to force a selector to inherit font colour from its grandparent, I would suggest that you give the selector and its grandparent a shared declaration for the font colour.

    Taking the blockquote example, assuming that body is the grandparent:

    body, blockquote em {
           color:[whatever];
    }
    
    
    blockquote {
           color:red;
    }
    

    And in the case of the unordered lists, it would be:

    body, ul ul {
           color:[whatever];
    }
    
    
    ul {
           color:blue;
    }
    
    0 讨论(0)
提交回复
热议问题