Using :before and :after to apply multiple background images
by martinwolf
HTML
<div class="mydiv"></div>
CSS
.mydiv {
position: relative; /* this is needed that the pseudo elements position according to the dimensions of .mydiv instead of body */
width: 70%; /* flexible width */
height: 200px;
background: #efefef;
}
.mydiv:before,
.mydiv:after {
content: ''; /* you have to define that to make the pseudo elements work */
position: absolute;
top: 0;
}
.mydiv:before {
left: 0;
width: 50px;
height: 70px;
background: red;
}
.mydiv:after {
right: 50px; /* positioning this image 50px from the right border of .mydiv wouldn't be possible with 'background' */
width: 60px;
height: 40px;
background: blue;
}