How can I select all elements except those inside divs with particular classes

前端 未结 1 774
清酒与你
清酒与你 2021-01-16 06:39

I\'d like to find a way to select all the makes of cars except those that are inside a div with the class discontinued or scrapped. Here\'s my mark

相关标签:
1条回答
  • 2021-01-16 07:11

    Unfortunately CSS selectors cannot traverse up parent elements, so if you are just trying to style them differently you may want to reverse your thought process and select ones that are .discontinued or .scrapped and apply overriding styles:

    .model {
      padding-left: 10px;
    }
    
    .make {
      color: green;
    }
    
    .scrapped .make,
    .discontinued .make {
      color: red;
    }
    <div class="car">
        <div class="make">NISSAN</div>
        <div class="model">MICRA</div>
    </div>
    <div class="discontinued">
        <div class="car">
            <div class="make">FORD</div>
            <div class="model">MONDEO</div>
        </div>
    </div>
    <div class="scrapped">
        <div class="car">
            <div class="make">SEAT</div>
            <div class="model">IBIZA</div>
        </div>
    </div>
    <div class="scrapped">
        <div class="preowned">
            <div class="car">
                <div class="make">SEAT</div>
                <div class="model">IBIZA</div>
            </div>
        </div>
    </div>
    <div class="car">
        <div class="make">HONDA</div>
        <div class="model">INTEGRA</div>
    </div>
    <div class="car">
        <div class="make">PEUGEOT</div>
        <div class="model">206</div>
    </div>
    <div class="car">
        <div class="make">TOYOTA</div>
        <div class="model">COROLLA</div>
    </div>

    0 讨论(0)
提交回复
热议问题