2011-06-13 69 views
0

我想对齐一个CSS形状与列表图标。对齐CSS3伪:形状之前与列表图像

现在它看起来是这样的:

enter image description here

但它应该是这样的:

enter image description here

我尝试使用的位置是:绝对的;相对的;和保证金,仍然没有。继承人现场测试:

http://jsfiddle.net/fzSrL/

CSS:

.services-info ul {} 
.services-info ul li { 
    background: #fff; 
    margin: 40px 0; 
    padding: 10px; 
    height: 115px; 
    width: 263px; 
} 

.services-info ul li:before { 
    content: ""; 
    width: 0; 
    height: 0; 
    border-top: 50px solid transparent; 
    border-right: 100px solid red; 
    border-bottom: 50px solid transparent; 
} 

.services-info ul li:nth-of-type(1) { 
    list-style-image: url(../images/fb-icon.png); 
} 

.services-info ul li:nth-of-type(2) { 
    list-style-image: url(../images/twitter-icon.png); 
} 

.services-info ul li:nth-of-type(3) { 
    list-style-image: url(../images/yt-icon.png); 
} 

我怎样才能将它们对齐在一起?或者将图像作为角落是更好的选择?

+1

':before'是不是新的CSS3。 – BoltClock 2011-06-13 16:35:19

回答

2

您需要在li上使用position: relative,然后在“箭头”(li:before)上使用position: absolute

然后,您可以用top/left和负margin-top的组合精确定位箭头。

参见:http://jsfiddle.net/fzSrL/2/

这种技术在此说明:http://css-tricks.com/absolute-positioning-inside-relative-positioning/

+0

负边距在Internet Explorer中无法正常工作? – nowayyy 2011-06-13 16:56:14

+0

负边界将正常工作。关于你正在使用的*其他*的东西:':before' /':after'在IE7中不起作用:http://caniuse.com/css-gencontent,'n-type-type'不起作用在IE浏览器直到第9版。它在IE9中工作得很好。 *(韵韵)* – thirtydot 2011-06-13 17:00:08

+0

虽然段落仍然下降.. – nowayyy 2011-06-13 17:43:49