I am new and would just like some understanding of the parent > child element and the preferred syntax for CSS.
Can someone explain to me why when I remove the > tag the code works for h1 in container-2, but if I leave it there the font size rule doesn't apply and instead follows the font-size rule for container-1?
.container-1 > h1 {
font-size: 1em;
}
.container-2 h1 {
font-size: 0.8em;
}
I am abit confused as the container-2 parent element is not the same as that of container 1, but it still applies. This is the html code for reference.
<div class="container-1">
<div class="content-1">
<!--image-->
<img src="images/edge of tomorrow.jpg" alt="Edge of Tomorrow" href="featured.html" class="featured-banner">
</div>
<!--headings-->
<div class="content-2">
<h1>Edge of Tomorrow</h1>
<h2>Rating: 4/5</h2>
<p>It leaves you on the edge, wishing for a tomorrow. An epic action movie with twists and turns along the way.</p>
<button class="featured-button"><a href="featured.html">Read more →</a></button>
</div>
</div>
</section>
<section class="movies">
<!--movies for screening, 2 columns by 2 rows-->
<!--First Row-->
<div class="container-2">
<!--movie1-->
<div class="col-1-3">
<!--movie 1 image-->
<img src="images/500 days of summer.jpg" alt="500 Days of Summer" href="movie1.html" class="movie-poster">
<h1>500 Days of Summer</h1>
<h2>Rating: 4/5</h2>
<h3>This is not a love story.</h3>
</div>
</div>
Is it something to do with specificity? Is the best practice for applying font rules then to use > child element tags, or without, i.e. .container-1 > h1 vs .container-1 h1?
Thank you!