629
技術社區[雲棲]
純 CSS 實現三角形尖角箭頭的實例
上次無意中發現了個使用純 CSS 實現三角形尖角箭頭的方法
https://blog.csdn.net/zhouzme/article/details/18901943
,但沒有怎麼用上,也沒有詳細完整的實例,今天剛好要用上,整理了下,寫個完整的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style type="text/css">
.area {
margin:100px auto;
width:300px;
height: 150px;
}
.item {
float:left; clear:both;
margin-bottom:23px;
}
/* 向上的箭頭 */
.dot-top {
font-size: 0;
line-height: 0;
border-width: 10px;
border-color: red;
border-top-width: 0;
border-style: dashed;
border-bottom-style: solid;
border-left-color: transparent;
border-right-color: transparent;
}
/* 向右的箭頭 */
.dot-right {
font-size: 0;
line-height: 0;
border-width: 10px;
border-color: red;
border-right-width: 0;
border-style: dashed;
border-left-style: solid;
border-top-color: transparent;
border-bottom-color: transparent;
}
/* 向下的箭頭 */
.dot-bottom {
font-size: 0;
line-height: 0;
border-width: 10px;
border-color: red;
border-bottom-width: 0;
border-style: dashed;
border-top-style: solid;
border-left-color: transparent;
border-right-color: transparent;
}
/* 向左的箭頭 */
.dot-left {
font-size: 0;
line-height: 0;
border-width: 10px;
border-color: red;
border-left-width: 0;
border-style: dashed;
border-right-style: solid;
border-top-color: transparent;
border-bottom-color: transparent;
}
</style>
</head>
<body>
<div >
<span ></span>
<span ></span>
<span ></span>
<span ></span>
</div>
</body>
</html>
可以通過設置 border-width 來調整箭頭的大小,這樣就不需要每次都去做圖了,非常方便,顏色可以隨時調整,真佩服那位老兄,以前雖然也發現 border 的兩邊是斜的但沒想到可以這樣來做尖角箭頭,太厲害了
顯示結果圖:

最後更新:2017-04-03 12:54:58