技术栈

纯 CSS 实现绘制各种三角形(各种角度)

Less,Sass,CSS

一、前言

三角形实现原理:宽度width为0;height为0;(1)有一条横竖边(上下左右)的设置为border-方向:长度 solid red,这个画的就是底部的直线。其他边使用border-方向:长度 solid transparent。(2)有两个横竖边(上下左右)的设置,若斜边是在三角形的右边,这时候设置top或bottom的直线,和右边的斜线。若斜边是在三角形的左边,这时候设置top或bottom的直线,和左边的斜线。

二、实现

2.1 Triangle Up
29UWmsYL8T8oUqP3A5RBQc7Wf4.png

#triangle-up {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid red;
}

2.2 Triangle Down
29IJv7syTT0UTzXMiygBtVo6ZG.png

#triangle-down {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-top: 100px solid red;
}

2.3 Triangle Left
29alsovh624Mb0bNQCzy5PqStS.png

#triangle-left {
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-right: 100px solid red;
    border-bottom: 50px solid transparent;
}

2.4 Triangle Right
2903hZu_EHdFiIzIBE-hx9c5P7.png

#triangle-right {
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-left: 100px solid red;
    border-bottom: 50px solid transparent;
}

2.5 Triangle Top Left
290aJgMTaALP0v3rkk7F-89ouQ.png

#triangle-topleft {
    width: 0;
    height: 0;
    border-top: 100px solid red;
    border-right: 100px solid transparent;
}

2.6 Triangle Top Right
29oP2ovlPPyPmuHhcREiGIMrl0.png

#triangle-topright {
    width: 0;
    height: 0;
    border-top: 100px solid red;
    border-left: 100px solid transparent;
}

2.7 Triangle Bottom Left
29FH81Y4G7Uo9bPbr2NBZHJEla.png

#triangle-bottomleft {
    width: 0;
    height: 0;
    border-bottom: 100px solid red;
    border-right: 100px solid transparent;
}

2.8 Triangle Bottom Right
29yQ0lH6MBfsOS0wGTZIcfiBmn.png

#triangle-bottomright {
    width: 0;
    height: 0;
    border-bottom: 100px solid red;
    border-left: 100px solid transparent;
}

原文链接:https://www.cnblogs.com/chengxs/p/11406278.html

点我评论
打赏本文
二维码


42

文章

22

标签