2015-05-27 27 views
-1

我有'li'-s导航菜单。 我想使这个李六方这样的:CSS六角形li怎么样?

enter image description here

我怎样才能做到这一点?

+5

请在您的问题中添加更多上下文,菜单项是以普通颜色还是在图像上显示E /梯度?添加您尝试过的示例代码也是一个优点,您的问题会被社区更好地接受。 –

回答

5

我会使用带有边框的伪元素。

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 
ul { 
 
    text-align: center; 
 
    font-size; 64px; 
 
    text-transform:uppercase; 
 
} 
 

 
li { 
 
    list-style: none; 
 
    display: inline-block; 
 
    background: black; 
 
    color: white; 
 
    padding:.5em 2em 0; 
 
    margin: 2em; 
 
    position: relative; 
 
} 
 

 
li:after { 
 
    content: ''; 
 
    position: absolute; 
 
    top:100%; 
 
    left:0; 
 
    width: calc(100% - 1em); /* twice border width */ 
 
    border:.5em solid transparent; 
 
    border-top-color:black; 
 
}
<ul> 
 
    <li>Text</li> 
 
    <li>Longer Text</li> 
 
    <li>Really Long Text</li> 
 
</ul>

+0

非常感谢你的男人! – IamGabros

1

我,像@Paulie_D,将使用伪元素,但我会在一个稍微不同的方式来创建它,(使用偏斜):

html,body{ 
 
    margin:0;padding:0; 
 
    background:url(http://www.lorempixel.com/900/900); 
 
    } 
 
li { 
 
    min-height: 30px; 
 
    width: 100px; 
 
    background: tomato; 
 
    position: relative; 
 
    margin: 15px; 
 
    display:inline-block; 
 
    text-align:center; 
 
    vertical-align:top; 
 
} 
 
li:before { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 100%; 
 
    right: 0; 
 
    width: 80%; 
 
    height: 10px; 
 
    transform: skewX(-45deg); 
 
    transform-origin: top right; 
 
    background: inherit; 
 
} 
 
li:after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 100%; 
 
    left: 0; 
 
    width: 80%; 
 
    height: 10px; 
 
    transform: skewX(45deg); 
 
    transform-origin: top left; 
 
    background: inherit; 
 
}
<ul> 
 
    <li>Text</li> 
 
    <li>Really Long Text which spans multiple lines</li> 
 
</ul>

+0

我会使用一个单一的伪与透视变换:D – Harry