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

谁说我不能喝 提交于 2019-12-22 01:28:06

问题


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?


回答1:


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.




回答2:


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:'@ ';}



回答3:


Of course you can use pseudo classes.They are quite well supported from IE8 and up.You can check the compatibility of any pseudoclass you are going to use here http://caniuse.com/#search=after

If you don't want a dot just use empty commas in content and then display:block and also specify height and width.

menu li:before {
    content: "";

    display:block;
    width:50px;
    height:50px;
    background:red;

}


来源:https://stackoverflow.com/questions/11168629/is-it-ok-to-use-multiple-pseudo-elements-in-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!