2015-05-27 26 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