Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to use multiple pseudo-elements in css?

I want to make a menu where each item is separated with a ·. To achieve this I use

menu li:before {
    content: "· ";
}

This is swell, but it generates a dot before the first item as well. Therefore, i would like to use :first-child pseudo-class as well. Can I do this?

like image 561
Himmators Avatar asked Jun 23 '12 10:06

Himmators


2 Answers

Sure you can - http://jsfiddle.net/WQBxk/

p:before {
    content: "BEFORE ";
    display: block;
}

p:first-child:before {
    content: "1ST";
    display: block
}
​

The bad - it won't work in IE7 and below. Not because of the multiple pseudo selectors, but because of non-supported :before - http://kimblim.dk/css-tests/selectors/

Just tested in IE8 - works well.

like image 161
Zoltan Toth Avatar answered Oct 01 '22 23:10

Zoltan Toth


Here is the working fiddle: http://jsfiddle.net/surendraVsingh/zRrLF/

<ul>
<li>lorem</li>
<li>lorem</li>
<li>lorem</li>
<li>lorem</li>
<li>lorem</li>
<li>lorem</li>

</ul>​

CSS:

li:before{content:'. ';}
li:first-child:before{content:'@ ';}
like image 1
SVS Avatar answered Oct 02 '22 00:10

SVS