2014-10-18 313 views
2

我想只能用css來畫一個箭頭導航,我寫了這個代碼繪製導航箭頭形狀的CSS

<span class="outer"> 
    <span class="inner"></span> 
</span> 

與風格

.outer { 
    width: 40px; 
    height: 40px; 
    border: 2px solid #000; 
    border-radius: 30px; 
    display: block; 
    position: relative; 
} 
.inner { 
    width: 0px; 
    height: 0px; 
    border-style: solid; 
    border-width: 10px 15px 10px 0; 
    border-color: transparent #000 transparent transparent; 
    position: absolute; 
    right: 35%; 
    top: 24%; 
} 

,但我想內三角是像這樣<,而不是播放按鈕。我分享了我的代碼JSFiddle

回答

1

您可以使用僞元素來獲得這種形狀。

唯一的缺點是您需要知道topleft值;他們不是相對於.inner的大小。

.outer { 
 
    width: 40px; 
 
    height: 40px; 
 
    border: 2px solid #000; 
 
    border-radius: 30px; 
 
    display: block; 
 
    position: relative; 
 
} 
 
.inner { 
 
    width: 0px; 
 
    height: 0px; 
 
    border-style: solid; 
 
    border-width: 10px 15px 10px 0; 
 
    border-color: transparent #000 transparent transparent; 
 
    position: absolute; 
 
    right: 35%; 
 
    top: 24%; 
 
} 
 

 
.inner:after{ 
 
    content:''; 
 
    width: 0px; 
 
    height: 0px; 
 
    border-style: solid; 
 
    border-width: 10px 15px 10px 0; 
 
    border-color: transparent #FFF transparent transparent; 
 
    position: absolute; 
 
    left: 5px; 
 
    top: -10px;  
 
}
<span class="outer"> 
 
    <span class="inner"></span> 
 
</span>

這只是放在的.inner頂部同樣大小的箭頭,但在碰一碰幾個像素。增加left樣式以使箭頭「更厚」。

+0

或者只是使用'less than'符號'<... ...以及更簡單的CSS標記。 – 2014-10-18 18:46:19

+0

@Paulie_D我本來以爲這個選項不用說了。特別是因爲OP在問題 – George 2014-10-18 18:49:46

+0

中使用它,你會這麼認爲......但我的意思是在你的「內容」屬性中......然後你可以用字體屬性來設計它......不需要邊框。 – 2014-10-18 18:51:08