0

Is there a way in CSS to select all the span tags inside the body and make them red except for any span tags inside a div element. What I am after is a way in CSS to select span elements outside of the div element but are still within the body. In the example below I only want "Span A" and "Span B" to be red and no other span to be affected.

<style>

body :not(div) span {
  color: red;
}

</style>

<body>
  <span>Span A</span>
    <article>
      <span>Span B</span>
    </article>

    <div>
      <span>Span C</span>
      <article>
        <span>Span D</span>
      </article>
    </div>
</body>
Adil
  • 235
  • 1
  • 5
  • 17
uionut351j
  • 27
  • 6
  • Use `body > span { ... }` – TiiJ7 Mar 12 '19 at 20:09
  • Sweet! Is there a CSS Selector to select a span if it was in the body, outside a div tag but inside an article `
    Span
    `
    – uionut351j Mar 12 '19 at 20:51
  • `body > article > span { ... }`. But I recommend you add a `class` or `id` on the element(s) and use that for styling; it works much easier and you can be sure it selects the correct elements. – TiiJ7 Mar 12 '19 at 21:00

0 Answers0