您现在的位置:首页 >> 前端 >> 内容

CSS画图形总结

时间:2017/3/21 9:28:00 点击:

  核心提示:CSS画图形总结三角形: #shape { width:0; height:0; border-left: 50px solid black; border-right: 70px solid bla...

CSS画图形总结

三角形:

CSS画图形总结

#shape { width:0; height:0; border-left: 50px solid black; border-right: 70px solid black; border-top: 50px solid red; border-bottom: 100px solid red; } 这里width,height设为0,则元素理解为一个小圆点 #triangle { width:0; height:0; border-left: 50px solid transparent;//黑色变为透明 border-right: 70px solid transparent; border-bottom: 100px solid red; }

CSS画图形总结

梯形: 首先看这段代码的效果

CSS画图形总结
#shape { width:100px; height:0; border-left: 50px solid black; border-right: 50px solid black; border-top: 100px solid red; border-bottom: 100px solid red; } height为0,width不为0,元素理解为一条线。 梯形: #trapezoid { width:100px; height:0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; }
CSS画图形总结

平行四边形: #parallelogram { width: 150px; height: 100px; margin-left:20px; -webkit-transform: skew(20deg);//倾斜20deg background: red; }

CSS画图形总结

椭圆形: #oval { width: 200px; height: 100px; background: red; border-radius: 100px / 50px;//用“/”隔开表示水平半径100px,垂直半径50px }

CSS画图形总结

圆形: #circle{ width:100px; height:100px; border-radius:50px; background:red; }

CSS画图形总结

3/4圆: #shape{ width:0; height:0; border-radius:50px; border-top:50px solid red; border-left:50px solid yellow; border-right:50px solid black; border-bottom:50px solid blue; }

CSS画图形总结

把缺的那块颜色设置为透明即为3/4圆 圆环: #ring{ width:100px; height:100px; border-radius:70px; border:20px solid black; background: transparent; }

CSS画图形总结

六角星: #six { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; position: relative; } #six:after { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 100px solid black; position: absolute; content: ""; //top: 30px; //left: -50px; }

CSS画图形总结

把伪元素after下移30px,左移50px,颜色换为红色,则可得到红色的六角星

CSS画图形总结

五角星: #five-stars { margin-left:100px; width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 150px solid red; position: relative; } //红色等腰三角形 #five-stars:before{ position: absolute; width: 0; height:0; border-left: 50px solid transparent; border-right:50px solid transparent; border-bottom: 50px solid blue; content: ""; top: 100px; left: -50px; }//蓝色等腰三角形 #five-stars:after{ position: absolute; width: 0; height:0; border-left: 80px solid transparent; border-right:80px solid transparent; border-top: 50px solid black; content: ""; top: 50px; left: -80px; }//黑色倒置三角形

CSS画图形总结

将蓝色换成白色,黑色换成红色,即为红色五角星

CSS画图形总结

爱心: #heart { position: relative; width: 100px; height: 90px; } #heart:before { position: absolute; content: ""; left: 50px; top: 0; width: 50px; height: 80px; background: red; border-radius: 25px 25px 0 0; transform: rotate(-45deg); transform-origin: 0 100%; } #heart:after { position: absolute; content: ""; left: 0; top: 0; width: 50px; height: 80px; background: black; border-radius: 25px 25px 0 0; transform: rotate(45deg); transform-origin :100% 100%; }

CSS画图形总结

利用伪元素画两个如下所示的图形,然后黑色的以右下角为圆心,顺时针转45度;红色以左下角为圆心,逆时针转45度。合成一个爱心。

CSS画图形总结

Tags:CS SS S画 画图 
作者:网络 来源:Showingbun