Skip to main content
fix example (missing =)
Source Link
ssc-hrep3
  • 16.3k
  • 8
  • 52
  • 96

How can I write a CSS Rule that selects all div.box that are not inside .container?

The following snippet is not working because there is a div without .container inside the div.container.

div:not(.container) .box {
   background:red; 
}
<div class"box">box<class="box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box<class="box">box</div></div>
</div>
<div class"box">box<class="box">box</div> <!-- select this -->

How can I write a CSS Rule that selects all div.box that are not inside .container?

The following snippet is not working because there is a div without .container inside the div.container.

div:not(.container) .box { background:red;}
<div class"box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box</div></div>
</div>
<div class"box">box</div> <!-- select this -->

How can I write a CSS Rule that selects all div.box that are not inside .container?

The following snippet is not working because there is a div without .container inside the div.container.

div:not(.container) .box {
   background:red; 
}
<div class="box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class="box">box</div></div>
</div>
<div class="box">box</div> <!-- select this -->

make it runnable
Source Link
ssc-hrep3
  • 16.3k
  • 8
  • 52
  • 96

How tocan I write a CSS Rule that selects all .box divsdiv.box that are NOTnot inside the container class.container?

<div class"box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box</div></div>
</div>
<div class"box">box</div> <!-- select this -->

ThisThe following snippet is not working because there is a divdiv without .container.container inside the container divdiv.container.

div:not(.container) .box { background:red;}

div:not(.container) .box { background:red;}
<div class"box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box</div></div>
</div>
<div class"box">box</div> <!-- select this -->

How to write a CSS Rule that selects all .box divs that are NOT inside the container class?

<div class"box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box</div></div>
</div>
<div class"box">box</div> <!-- select this -->

This is not working because there is a div without .container inside the container div.

div:not(.container) .box { background:red;}

How can I write a CSS Rule that selects all div.box that are not inside .container?

The following snippet is not working because there is a div without .container inside the div.container.

div:not(.container) .box { background:red;}
<div class"box">box</div> <!-- select this -->
<div class="container">
    <div>txt</div>
    <div><div class"box">box</div></div>
</div>
<div class"box">box</div> <!-- select this -->

edited tags
Link
j08691
  • 208.6k
  • 33
  • 270
  • 281
Source Link
Mike
  • 5.8k
  • 7
  • 44
  • 79
Loading