|
|
|
|
|
在前文中介紹過純CSS實(shí)現(xiàn)上下左右箭頭,本文將擴(kuò)展一下,介紹如何用純CSS實(shí)現(xiàn)各種方向的箭頭。
純CSS實(shí)現(xiàn)各種方向的箭頭
<ul>
<li><span class="arrow arrow-top"></span></li>
<li><span class="arrow arrow-right"></span></li>
<li><span class="arrow arrow-bottom"></span></li>
<li><span class="arrow arrow-left"></span></li>
<li><span class="arrow arrow-top-narrow"></span></li>
<li><span class="arrow arrow-top-wide"></span></li>
</ul>
<uL>
<li><span class="arrow arrow-top-left"></span></li>
<li><span class="arrow arrow-top-right"></span></li>
<li><span class="arrow arrow-bottom-left"></span></li>
<li><span class="arrow arrow-bottom-right"></span></li>
</ul>
ul {
margin: 1.5em 2em 1em;
text-align: center;
list-style: none;
}
ul + ul {
margin-top: -1em;
}
ul li {
display: inline-block;
margin: 40px;
}
/* arrow common style */
.arrow {
display: inline-block;
width: 15px;
height: 15px;
border-top: 2px solid #000;
border-right: 2px solid #000;
}
.arrow-top {
transform: rotate(-45deg);
}
.arrow-right {
transform: rotate(45deg);
}
.arrow-bottom {
transform: rotate(135deg);
}
.arrow-left {
transform: rotate(-135deg);
}
.arrow-top-narrow {
transform: rotate(-45deg) skew(-15deg, -15deg);
}
.arrow-top-wide {
transform: rotate(-45deg) skew(7deg, 7deg);
}
.arrow-top-left {
transform: rotate(-90deg) skew(-10deg, -10deg);
}
.arrow-top-right {
transform: rotate(0) skew(-10deg, -10deg);
}
.arrow-bottom-left {
transform: rotate(180deg) skew(-10deg, -10deg);
}
.arrow-bottom-right {
transform: rotate(90deg) skew(-10deg, -10deg);
}
上面css代碼中,可以通過.arrow
類來設(shè)置箭頭的粗細(xì)、大小和顏色,非常簡單。
其中width
和height
是設(shè)置大小,border-top
和border-right
設(shè)置粗細(xì)和顏色。
.arrow {
display: inline-block;
width: 15px;
height: 15px;
border-top: 2px solid #000;
border-right: 2px solid #000;
}