Not CSS selectors

后端 未结 8 1901
礼貌的吻别
礼貌的吻别 2020-11-28 11:05

Is there some kind of \"not\" CSS selector?

For example when I write the following line in my CSS, all input fields inside an tag with class classname will

相关标签:
8条回答
  • 2020-11-28 11:32

    Note that the negation pseudo class is in the Selectors Level 3 Recommendation and works in recent versions of Firefox, Chrome and Safari (at least). Sample code below.

    <html>
    <head>
    <title>Negation pseudo class</title>
    <style type="text/css">
        div {
        border: 1px solid green;
        height: 10px;
        }
        div:not(#foo) {
        border: 1px solid red;
        }
    </style>
    </head>
    <body>
        <div id="foo"></div>
        <div id="bar"></div>
        <div id="foobar"></div>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-11-28 11:34

    I think the closest you can get is to only affect direct descendants with a declaration

    This code for example will only affect input fields directly under divs with class "maincontent"

    div.maincontent > input {
      // do something
    }
    
    0 讨论(0)
提交回复
热议问题