By itself, a ::before
pseudo element is not visible. You will also need to give it a display
property, and some content. Otherwise, it won't show.
Now you haven't provided the HTML, but if I can presume that it's just a bunch of nested divs, the required extra CSS looks like this.
.content .cnt1 .block::before {
display:block; content:'';
height:200px; /* a height, any height */
}
Or for a more complete example: (never mind the background images)
.content .cnt1 .block::before {
display:block; content:'';
height:200px; /* a height, any height */
}
.content .cnt1 .block:nth-child(1)::before {
background: url(http://images.clipartpanda.com/number-clipart-niXxEn7iB.jpeg);
background-size: cover;
}
.content .cnt1 .block:nth-child(2)::before {
background: url(http://images.clipartpanda.com/clipart-numbers-9czE7pRpi.png);
background-size: cover;
}
.content .cnt1 .block:nth-child(3)::before {
background: url(http://images.clipartpanda.com/creation-clip-art-RTAE8d8TL.jpeg);
background-size: cover;
}
.content .cnt1 .block:nth-child(4)::before {
background: url(http://images.clipartpanda.com/number-clip-art-RcA6Axgji.png);
background-size: cover;
}
<div class="content">
<div class="cnt1">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
</div>
By the way, the notation for :before
with one colon is deprecated; the preferred way is ::before
.
Or, if you want to use :before
for compatibility with older browsers, then be warned that you can't use background-size
either.
That is, the only reason to use :before
is if you want to be compatible with IE8. :before
works in IE, ::before
doesn't.
But since IE8 doesn't support background-size
or nth-child()
, you won't get this particular example to work in IE8 anyway, so there's no need to bother.