css3画图那些事(三角形、圆形、梯形等)

闲来无事,写写图形。当时巩固一下css3吧.。前端小白,写的不好还请前辈多指教。

 

三角形

{  
    width: 0;
    height: 0;
    border-bottom: 140px solid red ;
    border-right: 70px solid transparent;
    border-left: 70px solid transparent;
}

圆形

{
        width: 0px;
        height: 0px;
        border:50px solid red;
        border-radius: 50%;
}

梯形

{
    width: 120px;
    height: 0px;
    border-bottom:120px solid red ;
    border-right: 60px solid transparent;
    border-left: 60px solid transparent;
}

平行四边形

{
        width: 0px;
        height: 0px;
        border:100px solid red ;
        transform: skew(30deg);
}

菱形实现方法有很多,这里只是两个三角形合并,也就是正三角和倒三角

.a{
    width: 0;
    height: 0;
    border-bottom: 140px solid red ;
    border-right: 70px solid transparent;
    border-left: 70px solid transparent;                            
}
.b{
    width: 0;
    height: 0;
    border-top : 140px solid red;
    border-left : 70px solid transparent; 
    border-right : 70px solid transparent; 
    }

椭圆形

{
    width: 200px;
    height: 50px;
    border:1px solid red;
    border-radius:100px; 
}

五边形(这里使用一个三角形加一个正方形实现)

    .a{
        width: 0;
        height: 0;
        border-bottom  : 140px solid red;
        border-left : 70px solid transparent; 
        border-right : 70px solid transparent;                 
    }

    .b{
        width: 140px;
        height: 140px;
        display: inline-block;
        border:1px solid red;
        background-color: red ;
    }

贪吃蛇蛇头你敢信?哈哈

 

{
        width: 0px;
        height: 0px;
        border-radius: 50%;
        border:140px solid red;
        border-right :140px solid transparent; 
}

 

扇形

 

{
        width: 0px;
        height: 0px;
        border-radius: 50%;
        border :140px solid transparent; 
        border-bottom:140px solid red;
}

 登录icon(两个div,其中一个div设置一个margin-top的负值,移上来就好了)

 

    .a{
        width: 0px;
        height: 0px;
        border-radius: 50%;
        border: 30px solid #000;
    }
    .b{
        width: 0px;
        border: 50px solid #000;
        border-top-right-radius: 50px;
        border-top-left-radius: 50px;
        border-top-width: 25px;
        border-bottom-width: 25px;
    }

再来一个小视频 (用4个div拼接起来,两个圆圈,一个长方形,一个梯形就好了)

    .a{    
        display: inline-block;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: 1px solid #000;
    }

    .b{    
        display: inline-block;
        width: 30px;
        height: 30px;
        border-radius: 50%;
        border: 1px solid #000;
    }
    .c{
        width: 80px;
        height: 50px;
        border: 1px solid #000;
        border-radius: 10px;
        }
    .d{
        height: 40px;
        border-right: 30px solid #000;
        border-top: 16px solid transparent;
        border-bottom: 16px solid transparent;
        border-radius: 10px;
        }



<div>
    <div class="a" style="margin-left:160px ;margin-top: 100px;"></div>
    <div class="b" ></div>
</div>
<div>
    <div class="c" style="margin-left:150px ; display: inline-block;vertical-align: top;"></div>
    <div class="d" style="margin-left:0px ; display: inline-block;margin-top: -10px;"></div>
</div>

再来一个垃圾桶 三个图形叠加。正方形,椭圆,和梯形。然后在设置一个倾斜就好了

.a{    
        width: 0px;
        height: 0px;
        border-radius: 4px;
        border: 8px solid #000;
        border-top-width: 0;
        margin-left:164px ;
        margin-top: 100px;
    }

    .b{    
        width: 0px;
        height: 0px;
        border-radius:8px ;
        border-top: 15px solid #000;
        border-left: 132px solid #000;
        margin-left: 108px;
    }
    .c{
        width: 78px;
        border-bottom-width: 100px;
        border-top: 100px solid #000;
        border-left: 18px solid transparent;
        border-right: 18px solid transparent;
    }



    <div style="display: inline-block;transform: rotate(9deg);">
        <div class="a"></div>
        <div class="b"></div>
    </div>
    <div style="margin-left: 110px; margin-top: 18px;">
        <div class="c"></div>
    </div>
posted @ 2018-07-23 18:28  我在广州写bug  阅读(1891)  评论(0编辑  收藏  举报