Is there a way to have the equivalent of multiple :before and :after pseudo-elements in CSS?

Posted by Sergey Basharov on Stack Overflow See other posts from Stack Overflow or by Sergey Basharov
Published on 2013-10-23T21:56:13Z Indexed on 2013/10/24 9:55 UTC
Read the original article Hit count: 220

Filed under:
|

Currently I have this markup that represents an icon container and some elements styled with CSS inside it that in the end show as graphic icon.

    <div class="icon">
        <div class="icon-element1"></div>
        <div class="icon-element2"></div>
        <div class="icon-element3"></div>
    </div>

The number of the child elements can be different depending on the complexity of the icon.

What I want is to somehow move as much as possible to CSS stylesheet, so that ideally I would have only <div class="icon"></div> and the rest would just render from CSS styles, something close in concept to :before/:after, a kind of virtual divs. I don't want to use JavaScript to add the elements dynamically. It would be possible to do this if we had multiple :before/:after.

Here is an example of an icon I get by using the markup from above:

Icon

As you can see, there are 3 child elements representing gray case, white screen and turquoise button.

Please advise, how I can simplify this markup so that not to have to put all the divs each time I want this icon to be shown.

© Stack Overflow or respective owner

Related posts about html

Related posts about css