国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

純CSS繪制三角形箭頭效果

2024-07-11 08:31:03
字體:
來源:轉載
供稿:網友

使用純CSS,你只需要很少的代碼就可以創作出各種瀏覽器都兼容的三角形箭頭!

CSS代碼


復制代碼
代碼如下:
/* create an arrow that points up */
div.arrow-up {
width: 0;
height: 0;
border-left: 5px solid transparent; /* left arrow slant */
border-right: 5px solid transparent; /* right arrow slant */
border-bottom: 5px solid #2f2f2f; /* bottom, add background color here */
font-size: 0;
line-height: 0;
}
/* create an arrow that points down */
div.arrow-down {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #2f2f2f;
font-size: 0;
line-height: 0;
}
/* create an arrow that points left */
div.arrow-left {
width: 0;
height: 0;
border-bottom: 5px solid transparent; /* left arrow slant */
border-top: 5px solid transparent; /* right arrow slant */
border-right: 5px solid #2f2f2f; /* bottom, add background color here */
font-size: 0;
line-height: 0;
}
/* create an arrow that points right */
div.arrow-right {
width: 0;
height: 0;
border-bottom: 5px solid transparent; /* left arrow slant */
border-top: 5px solid transparent; /* right arrow slant */
border-left: 5px solid #2f2f2f; /* bottom, add background color here */
font-size: 0;
line-height: 0;
}

繪制這些三角形的關鍵在于,你要讓箭頭所指方向的兩個側邊有很粗的邊框。而背向箭頭方向的一邊也是同樣粗的邊框,而這條邊的顏色就是你的三角形的顏色。邊框越粗,三角形越大。用這種方法你可以繪制出各種顏色、各種大小、各種朝向的箭頭。最妙的是,你只需要幾行CSS代碼就能實現這種效果。

使用:before和:after繪制CSS三角形

上面的CSS例子使用的是真正的頁面元素進行繪制,但有時候這個真正的元素還有它用,你不能走上面直接進行操作,這是怎么辦?純CSS的三角形其實還可以使用偽元素(pseudo-element)進行繪制。下面就是繪制方法:

復制代碼
代碼如下:
div.tooltip {
/* tooltip content styling in here; nothing to do with arrows */
}
/* shared with before and after */
div.tooltip:before, div.tooltip:after {
content: ' ';
height: 0;
position: absolute;
width: 0;
border: 10px solid transparent; /* arrow size */
}
/* these arrows will point up */
/* top-stacked, smaller arrow */
div.tooltip:before {
border-bottom-color: #fff; /* arrow color */</p><p> /* positioning */
position: absolute;
top: -19px;
left: 255px;
z-index: 2;
}
/* arrow which acts as a background shadow */
div.tooltip:after {
border-bottom-color: #333; /* arrow color */</p><p> /* positioning */
position: absolute;
top: -24px;
left: 255px;
z-index: 1;
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 互助| 台湾省| 陇川县| 缙云县| 铜鼓县| 光泽县| 岳西县| 明光市| 阿鲁科尔沁旗| 延吉市| 安新县| 青岛市| 宣汉县| 邯郸县| 娱乐| 修武县| 建水县| 沁源县| 河东区| 万荣县| 蒙山县| 五河县| 湘潭市| 交口县| 通海县| 永城市| 酉阳| 如皋市| 洛扎县| 石景山区| 兴安盟| 松江区| 绥宁县| 新兴县| 岫岩| 陆河县| 建湖县| 西畴县| 准格尔旗| 乌审旗| 奎屯市|