It seems like I have encountered a potential bug with the General Sibling Selector. When I use p ~ div
, the selector does not work as expected. However, when I replace p
with the specific class name text_paragraph
, it works fine. You can view my code and fiddle below to see the issue.
Fiddle https://jsfiddle.net/t2Ljmgar/
.outer_container {
margin: 20px;
padding-bottom: 10px;
background-color: rgba(216, 23, 27, 1);
border: 1px solid rgba(0, 0, 0, 1);
}
.text_paragraph {
margin: 10px 10px 0px 10px;
padding-left: 10px;
font: 2em/4em Arial, Helvetica, "sans-serif";
color: rgba(64, 64, 64, 1.00);
border: 1px solid rgba(0, 0, 0, 1);
background-color: rgba(180, 180, 120, 1);
}
.text_container {
margin: 10px 10px 0px 10px;
padding-left: 10px;
font: 1.5em/3em Arial, Helvetica, "sans-serif";
color: rgba(64, 64, 64, 1.00);
background-color: rgba(215, 215, 251, 1);
}
p ~ div {
background-color: rgba(0, 255, 255, 1);
}
<div class="outer_container">
<p class="text_paragraph">Important header up top.</p>
<div class="text_container">This is the first text on the page.</div>
<div class="text_container">This is the second text on the page.</div>
<div class="text_container">This is the third text on the page.</div>
</div>
By changing P to the specific class name, the selector starts working correctly.
.outer_container {
margin: 20px;
padding-bottom: 10px;
background-color: rgba(216, 23, 27, 1);
border: 1px solid rgba(0, 0, 0, 1);
}
.text_paragraph {
margin: 10px 10px 0px 10px;
padding-left: 10px;
font: 2em/4em Arial, Helvetica, "sans-serif";
color: rgba(64, 64, 64, 1.00);
border: 1px solid rgba(0, 0, 0, 1);
background-color: rgba(180, 180, 120, 1);
}
.text_container {
margin: 10px 10px 0px 10px;
padding-left: 10px;
font: 1.5em/3em Arial, Helvetica, "sans-serif";
color: rgba(64, 64, 64, 1.00);
background-color: rgba(215, 215, 251, 1);
}
.text_paragraph ~ div {
background-color: rgba(0, 255, 255, 1);
}
<div class="outer_container">
<p class="text_paragraph">Important header up top.</p>
<div class="text_container">This is the first text on the page.</div>
<div class="text_container">This is the second text on the page.</div>
<div class="text_container">This is the third text on the page.</div>
</div>