I'm trying to use pseudo-selectors rather than tag things with an individual ID if I can help it, as I have been led to believe that this is better coding.
I have three text containers, and I would like the middle one to have a different background colour for design purposes. Whichever pseudo-selector I use, I unable to select only the container, and not its children. Having experimented with nth-of-type and nth-child, I can either select the container as well as text within it, or select the container as well as text within another container.
How do I use a pseudo-selector to select only the middle container and not its contents?
My code:
<section id="section">
<span class="container">
<h3>Heading 1</h3>
<p>Text</p>
</span>
<span class="container">
<h3>Heading 2</h3>
<p>Text</p>
</span>
<span class="container">
<h3>Heading 3</h3>
<p>Text</p>
</span>
</section> ```
Css:
#section :nth-child(3) {
background-color: red;
}