Currently, I am enrolled in an online web development course and have been working on creating webpages to grasp the concepts of HTML and CSS. However, I encountered an issue where the font-family rules in my p and h3 elements were overriding the font-family rules specified in certain ID selectors on the page. I managed to find a workaround by chaining selectors, but I am still puzzled as to why this conflict occurred in the first place.
Here is a snippet of the HTML I am trying to format:
h3 {
font-family: Helvetica, sans-serif;
font-size: 24px;
}
p {
font-family: "Roboto", sans-serif;
}
.font-container {
display: inline-block;
width: 45%;
}
.caps {
text-transform: uppercase;
}
#helvetica{
font-family: Helvetica, sans-serif;
}
#roboto{
font-family: "Roboto", sans-serif;
}
#lora{
font-family: "Lora", serif;
}
<div class="container">
<h2>Fonts</h2>
<div class="font-container" id="helvetica">
<h3>Helvetica</h3>
<div class="normal">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
<div class="caps">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
</div>
<div class="font-container" id="roboto">
<h3>Roboto</h3>
<div class="normal">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
<div class="caps">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
</div>
<div class="font-container" id="lora">
<h3>Lora</h3>
<div class="normal">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
<div class="caps">
<p>The quick brown fox jumps over the lazy dog.</p>
<p><em>The quick brown fox jumps over the lazy dog.</em></p>
<p><strong>The quick brown fox jumps over the lazy dog.</strong></p>
</div>
</div>
Upon inspecting with Chrome DevTools, it became apparent that the font-family for all text within this div was inheriting from the p and h3 rules. Can anyone shed some light on why this behavior is occurring?