Daily-Question icon indicating copy to clipboard operation
Daily-Question copied to clipboard

【Q190】使用 CSS 如何画一个三角形

Open shfshanyue opened this issue 5 years ago • 7 comments

shfshanyue avatar Jan 27 '20 11:01 shfshanyue

.triangle { width: 0px; height: 0px; border: 100px solid; border-color: transparent transparent rgba(134, 241, 143,1) transparent; }

Sumarina avatar Apr 09 '20 10:04 Sumarina

.container{ width: 0; height:0; border-color: transparent; border-left: 100px solid #f00; }

canddyBrea avatar May 06 '20 14:05 canddyBrea

    .triangle {
      width: 0;
      border: 100px solid transparent;
      border-bottom: 100px solid rgba(66, 142, 212, 0.4);
    }

Innocentw avatar Jul 30 '20 09:07 Innocentw

 .container{
width:0;
border:100px solid transparent;
border-bottom-color:#000;
}

wangliang000 avatar Mar 02 '22 15:03 wangliang000


        .triangle {
            margin: 0 auto;
            width: 50vh;
            height: 50vh;
            background-color: aqua;
            /* 
                画多边形: 
                polygon(x y, x y, ...)
                一组 x y, 代表一个点
                x: 往右增加
                y: 往下增加
            */
            clip-path: polygon(0 0, 0% 100%, 100% 100%);
        }

image

cy948 avatar May 14 '22 13:05 cy948

.box {
    width: 0;
    height: 0;
    border:100px solid transparent;
    border-bottom-color: blue;
}

zjunbin1286 avatar Jun 25 '22 15:06 zjunbin1286

CSS实现三角形的核心,在于设置元素宽高为0,宽高由border撑起,设置其他三个border为透明 https://stackblitz.com/edit/web-platform-nkudf7?file=index.html,styles.css

Neisun avatar Aug 25 '23 07:08 Neisun