<!-- :empty -->
<section class="example-cntr empty">
<h1>CSS <code>:empty</code> pseudo-class</h1>
<p>The <code>:empty</code> pseudo-class targets elements that have no content of any kind in them, at all.</p>
<p>If it has any type of character, even a space, then the element is <span class="underline">not</span> considered empty.</p>
<p>In the following example <span class="red">Red</span> boxes have content and <span class="yellow">Yellow</span> boxes are empty:</p>
<div class="flex-ctnr">
<div>I have content, thus I'm red…</div>
<div> </div> <!-- A space is considered content so it’s red -->
<div></div> <!-- Totally empty element so it’s yellow -->
<div><!-- This comment inside isn’t considered content so it’s yellow --></div>
</div>
</section>
//:empty
.empty {
.flex-ctnr div {
display: flex;
flex: 1;
justify-content: center;
align-items: center;
margin: 0 5px;
padding: 3px;
background: $r;
}
.flex-ctnr div:empty { background: $y; }
}
//Styling stuff not needed for demo
body { text-align: left; }
.example-cntr {
max-width: 800px;
margin: auto;
padding: 20px 50px;
box-shadow: 0 1px 2px rgba(black,.3);
background: rgba(black,.15);
}
h1 {
text-transform: none;
border-bottom: #636363 1px dotted;
code {
display: inline-block;
margin-bottom: 10px;
color: $y;
background: none;
box-shadow: none;
}
}
.flex-ctnr {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: 20px;
}
code { font-size: 1em; }
.underline { text-decoration: underline; }
$r: lighten($r,12);
.red { color: $r; }
.green { color: $g; }
.yellow { color: $y; }
View Compiled
This Pen doesn't use any external JavaScript resources.