css如何绘制特殊图形的方法示例

网站建设 2023-01-28 21:39www.1681989.com免费网站

一、三角形

border边框设置

代码

width: 300px;
height: 300px;
background: red;
border: 40px solid black;
border-left-color: blue;
border-bottom-color: yellow;
border-right-color: pk;
border--color: #008800;

花特殊图形的时候需要将宽高设置成0

效果

代码

width: 0;
height: 0;
background: transparent;
border: 40px solid black;
border-left-color: blue;
border-bottom-color: yellow;
border-right-color: pk;
border--color: #008800;

1、等腰三角形将其他的边的border设置成透明

代码

width:0;
height: 0;
background: transparent;
border: 40px solid black;
border-left-color: transparent;
border-bottom-color: yellow;
border-right-color: transparent;
border--color: transparent;

2、直角三角形

代码先写出个完整的div,再使用border--width0;来截取三角形

border--width/border-bottom-width:0=》就是在中间横着劈开一道,保留上边或者下边

border-left-width/border-right-width:0=》就是在中间竖着劈开一道,保留左边或者右边

.rightAngle{
    width: 0;
    height: 0;
    background: transparent;
    border: 40px solid black;
    border-left-color: blue;
    border-bottom-color: yellow;
    border-right-color: pk;
    border--color: #008800;
    border--width: 0;
    border-left-width: 0;
    border-right-color: transparent;
}

3、梯形

彩带图形

代码

width: 300px;
height: 0;
background: transparent;
border: 40px solid #008800;
border-left-color: transparent;
border-bottom-color: yellow;
border-right-color: transparent;
border--color: #008800;

梯形

代码将上面彩带图形的宽度减少,然后将上面的梯形设置为透明

width: 100px;
height: 0;
background: transparent;
border: 40px solid #008800;
border-left-color: transparent;
border-bottom-color: #008800;
border-right-color: transparent;
border--color: transparent;

通过设置长度和高度,以及设置border的透明度来拼凑成想要的图形 4、圆形

4、图形

代码 使用border-radius:50%;

.circle{
    width: 100px;
    height: 100px;
    border: 0;
    border-radius: 50%;
    background-color: orange;
}

5、椭圆

图形

代码

.ellipse{
    width: 200px;
    height: 120px;
    background-color: orange;
    border--left-radius: 50%;
    border--right-radius: 50%;
    border-bottom-left-radius: 50%;
    border-bottom-right-radius: 50%;
}

一个displayblock的元素设定宽高之后表现为矩形。通过设定border-radius可以得到圆角矩形,圆形和椭圆形。

在使用border-radius时,有几点可能需要注意一下

  • border-radius,可以分别对4个角进行设定。 例如上图border--left-radius: apx bpx;
  • border-xxx-xxx-radius的两个值分别代表着椭圆长轴和短轴长度的一半,通常简写的时候例如border--left-radius: 10px;(border--left-radius:10px 10px;) 表明长轴和短轴的长度均为20px,也就是半径为10px的圆形(圆角部分)。
  • 当使用百分比数值时,a 相对于width, b相对于height 6、特殊图形

(1)斜边三角形

图形

代码先画个等边三角形,然后再转换角度

.beveledTriangle{
    marg: 50px;
    width: 0;
    height: 0;
    border: 20px solid #2b81af;
    border--width: 40px;
    border--color:transparent;
    border-bottom-width: 40px;
    border-bottom-color: transparent;
    border-left-width: 0;
    border-right-color: #008800;
    border-right-width: 25px;
    transform-orig:center center;
    transform:rotateY(-180deg) rotate(-44deg)  ;
}

(2)绘制一条“小尾巴”

图形

代码

.tail{
    marg: 50px;
    width: 100px;
    height: 70px;
    border--right-radius: 70px 70px;
    border-right:6px solid #000000;
}

当对一个角应用圆角样式, 如果这个角相邻的两个boeder一个有定义而一个无定义 ,那么绘制的结果就是有粗到细的“小尾巴了”

7、绘制QQ图案(取自AlloyTeam案例)

图形

代码

 

<a id="qq" href="http://.alloyteam." target="_blank">
    <div class='head'>
        <div class='left eye'>
            <div class="nerLeftEye">
            </div>
        </div>
        <div class='right eye'>
            <div class="nerRightEye">
                <div class="fix"></div>
            </div>
        </div>
        <div class='mouthTopContaer'>
            <div class='mouthTop'></div>
        </div>
        <div class="mouthBottomContaer">
            <div class="mouthBottom"></div>
        </div>
        <div class="lipsContaer">
            <div class="lips">
                <div class="lipShadow left">
                </div>
                <div class="lipShadow right">
                </div>
            </div>
        </div>
    </div>
    <div class="body">
        <div class="nerWrapper">
            <div class="ner">
            </div>
        </div>
        <div class="outterWrapper">
            <div class = 'outter'>
            </div>
        </div>
        <div class="scarf">
            <div class="scarfShadow">
            </div>
            <div class="scarfShadowRight">
            </div>
        </div>
        <div class="scarfEnd">
            <div class="scarfEndShadow">
            </div>
        </div>
    </div>
    <div class="handWrapper">
        <div class="leftHandTopContaer">
            <div class="leftHandTop">
            </div>
        </div>
        <div class="leftHandBottomContaer">
            <div class="leftHandBottom">
            </div>
        </div>
        <div class="rightHandTopContaer">
            <div class="rightHandTop">
            </div>
        </div>
        <div class="rightHandBottomContaer">
            <div class="rightHandBottom">
            </div>
        </div>
    </div>
    <div class='footWrapper'>
        <div class="leftFootTopWrapper">
            <div class="leftFootTop">

            </div>
        </div>
        <div class="leftFootBottomWrapper">
            <div class="leftFootBottom">
            </div>
        </div>
        <div class='toe left'></div>
        <div class="rightFootTopWrapper">
            <div class="rightFootTop">
            </div>
        </div>
        <div class="rightFootBottomWrapper">
            <div class="rightFootBottom">
            </div>
        </div>
        <div class='toe right'></div>
    </div>
</a>

<style>
    body{
        marg: 0;
        paddg:0;
        font: 12px Tahoma, arial, sans-serif;
    }
    #mask {
        position: absolute;
        opacity: 0.2;
        :0;
        left:0;
    }

    header{
        font-family: 'Segoe UI Light','Segoe UI','Microsoft Jhenghei','寰杞闆呴粦',sans-serif;
        color: #666;
        font-size: 50px;
        text-align: center;
        marg-:50px;
    }

    .team {
        font-size: 0.6em;
    }

    .team a{
        color:#5FB7E9;
        text-decoration: none;
    }

    .team a:hover{
        color:#4B9BC9;
    }
    /
      LOGO
     /

    #qq {
        width: 420px;
        height: 400px;
        marg: 0 auto;
        marg-: 30px;
        position: relative;
        display:block;
    }

    .head{
        position: absolute;
        :18px;
        left: 96px;
        width: 234px;
        height: 185px;
        border: 1px solid #000;
        border--left-radius: 117px 117px;
        border--right-radius: 117px 117px;
        border-bottom-left-radius: 117px 68px;
        border-bottom-right-radius: 117px 68px;
        z-dex:10;
        background: #000;
    }

    .eye{
        width: 44px;
        height: 66px;
        border:1px solid #000;
        border-radius: 50% 50%;
        position: absolute;
        background: #fff;
    }

    .left.eye{
        left:62px;
        :50px;
    }

    .right.eye{
        left:123px;
        :50px;
    }

    .nerLeftEye{
        position: absolute;
        : 20px;
        left: 20px;
        width: 18px;
        height: 24px;
        border-radius: 50%;
        border: 1px solid #000;
        background: #000;
    }

    .nerLeftEye:after{
        content: "";
        position: absolute;
        width: 6px;
        height: 8px;
        background: white;
        z-dex: 11;
        : 6px;
        left: 9px;
        border-radius: 50%;
    }

    .nerRightEye{
        position: absolute;
        width: 18px;
        height: 20px;
        : 20px;
        left: 8px;
        border--left-radius: 50% 90%;
        border--right-radius: 50% 90%;
        border-bottom-left-radius: 50% 10%;
        border-bottom-right-radius: 50% 10%;
        background: black;
        box-shadow: 0 -1px 2px black;
    }

    .nerRightEye:after{
        content: "";
        position: absolute;
        width: 10px;
        height: 13px;
        bottom: -1px;
        left: 4px;
        border--left-radius: 50% 100%;
        border--right-radius: 35% 80%;
        background: white;
    }

    .fix {
        position: absolute;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: black;
        : 17px;
    }

    .fix:after{
        content: "";
        position: absolute;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: black;
        : 0;
        left: 14px;
    }

    .mouthTopContaer {
        position: absolute;
        width: 158px;
        height: 29px;
        z-dex: 1;
        : 120px;
        left: 39px;
        overflow: hidden;
    }
    .mouthTop{
        width: 158px;
        height: 34px;
        position: absolute;
        z-dex: 1;
        border:1px solid #FFA600;
        background: #FFA600;
        : 0;
        left: 0;
        border--left-radius: 45% 34px;
        border--right-radius: 45% 34px;
        /background-color: #FFA600; /
    }

    .mouthBottomContaer {
        position: absolute;
        width: 158px;
        height: 15px;
        z-dex: 1;
        : 146px;
        left: 39px;
        overflow: hidden;
    }
    .mouthBottom{
        width: 158px;
        height: 24px;
        position: absolute;
        z-dex: 1;
        border:1px solid #FFA600;
        background: #FFA600;
        border-:none;
        : -4px;
        left: 0;
        border-bottom-left-radius: 45% 24px;
        border-bottom-right-radius: 45% 24px;
        background-color: #FFA600;
    }

    .lips{
        border: 1px solid #FFA600;
        background: #FFA600;
        width: 116px;
        height: 24px;
        position: absolute;
        : 146px;
        left: 60px;
        border-: none;
        border-bottom-left-radius: 50% 100%;
        border-bottom-right-radius: 50% 100%;
    }

    .lipShadow {
        width: 0px;
        height: 0px;
        position: absolute;
        z-dex: 2;
        border-: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-right: 8px solid black;
        -webkit-transform-orig:  right;
        -webkit-transform: rotate(-60deg);
        -moz-transform-orig:  right;
        -moz-transform: rotate(-60deg);
        -o-transform-orig:  right;
        -o-transform: rotate(-60deg);
        transform-orig:  right;
        transform: rotate(-60deg);
        left: -12px;
        : 4px;
    }

    .lipShadow.right{
        left:114px;
        -webkit-transform: rotate(60deg) rotateY(180deg);
        -moz-transform: rotate(60deg) rotateY(180deg);
        -o-transform: rotate(60deg) rotateY(180deg);
        transform: rotate(60deg) rotateY(180deg);
    }

    .body{
        width: 326px;
        height: 300px;
        /border: 1px solid black;/
        : 135px;
        left: 48px;
        position: absolute;
    }

    .scarf {
        border: 4px solid #000;
        position: absolute;
        background: #FB0009;
        z-dex: 5;
        width: 258px;
        height: 110px;
        : -2px;
        left: 34px;
        border--left-radius: 30px 34px;
        border--right-radius: 38px 34px;
        border-bottom-left-radius: 50% 76px;
        border-bottom-right-radius: 50% 76px;
        border-: none;
    }

    .scarfShadow {
        position: absolute;
        border-: 6px solid #000;
        width: 60px;
        height: 70px;
        : 0px;
        left: 6px;
        border--left-radius: 90px 120px;
        border--right-radius: 30px 30px;
        -webkit-transform: rotate(-79deg);
        -moz-transform: rotate(-79deg);
        -o-transform: rotate(-79deg);
        transform: rotate(-79deg);
    }

    .scarfShadowRight {
        position: absolute;
        border-right: 6px solid black;
        width: 100px;
        height: 70px;
        : 8px;
        left: 143px;
        border-bottom-right-radius: 70px 70px;
        z-dex: 6;
    }

    .scarfEnd{
        position: absolute;
        width: 52px;
        height: 64px;
        z-dex: 4;
        : 90px;
        border: 3px solid black;
        left: 74px;
        border-bottom-left-radius: 50% 43%;
        border-bottom-right-radius: 15px;
        border--left-radius: 20% 57%;
        background: #FB0009;
    }

    .scarfEndShadow{
        position: absolute;
        border-: 6px solid black;
        width: 20px;
        height: 20px;
        : 6px;
        left: 12px;
        border--left-radius: 30px 30px;
        -webkit-transform-orig:  right;
        -moz-transform-orig:  right;
        -o-transform-orig:  right;
        transform-orig:  right;
        z-dex: 10;
        -webkit-transform: skewX(4deg) scaleY(1.5) rotate(-60deg);
        -moz-transform: skewX(4deg) scaleY(1.5) rotate(-60deg);
        -o-transform: skewX(4deg) scaleY(1.5) rotate(-60deg);
        transform: skewX(4deg) scaleY(1.5) rotate(-60deg);

    }

    .nerWrapper{
        position: absolute;
        overflow: hidden;
        width: 280px;
        height: 200px;
        left: 30px;
        : 76px;
    }

    .ner {
        border: 1px solid #000;
        width: 218px;
        position: absolute;
        height: 210px;
        border-radius: 50%;
        left: 25px;
        : -71px;
        z-dex: 4;
        background: #fff;
    }

    .outterWrapper{
        width: 262px;
        left: 32px;
        height: 250px;
        position: absolute;
        : 54px;
        overflow: hidden;
    }

    .outter{
        border: 1px solid #000;
        width: 260px;
        height: 250px;
        border-radius: 125px;
        position: absolute;
        : -84px;
        z-dex: 3;
        background: #000;
    }

    .handWrapper{
        position: absolute;
        : 219px;
        left: 7px;
    }


    .leftHandTopContaer{
        width: 118px;
        height: 26px;
        position: absolute;
        z-dex: 1;
        : 55px;
        left: 50px;
        -webkit-transform-orig: bottom left;
        -webkit-transform: rotate(-70deg);
        -moz-transform-orig: bottom left;
        -moz-transform: rotate(-70deg);
        -o-transform-orig: bottom left;
        -o-transform: rotate(-70deg);
        transform-orig: bottom left;
        transform: rotate(-70deg);
        overflow: hidden;
    }

    .leftHandTop{
        width: 128px;
        height: 54px;
        border: 1px solid #050346;
        position: absolute;
        border--left-radius: 44% 38px;
        border--right-radius: 56% 33px;
        background: #000;
    }

    .leftHandBottomContaer {
        width: 100px;
        height: 30px;
        position: absolute;
        z-dex: 1;
        : 78px;
        left: 50px;
        -webkit-transform-orig:  left;
        -webkit-transform: rotate(-70deg);
        -moz-transform-orig:  left;
        -moz-transform: rotate(-70deg);
        -o-transform-orig:  left;
        -o-transform: rotate(-70deg);
        transform-orig:  left;
        transform: rotate(-70deg);
        overflow: hidden;
    }

    .leftHandBottom{
        width: 128px;
        height: 44px;
        border: 1px solid #050346;
        background: #000;
        border-: none;
        position: absolute;
        border-bottom-left-radius: 48% 20px;
        border-bottom-right-radius: 52% 23px;
        : -26px;
    }


    .rightHandTopContaer{
        width: 118px;
        height: 34px;
        position: absolute;
        z-dex: 3;
        : 47px;
        left: 240px;
        -webkit-transform-orig: bottom right;
        -webkit-transform: rotate(65deg);
        -moz-transform-orig: bottom right;
        -moz-transform: rotate(65deg);
        -o-transform-orig: bottom right;
        -o-transform: rotate(65deg);
        transform-orig: bottom right;
        transform: rotate(65deg);
        overflow: hidden;
    }

    .rightHandTop{
        width: 148px;
        height: 54px;
        border: 1px solid #050346;
        position: absolute;
        border--right-radius: 41% 54px;
        border--left-radius: 59% 48px;
        background: black;
        left: -30px;
        -webkit-transform: rotateY(-180deg);
        -moz-transform: rotateY(-180deg);
        -o-transform: rotateY(-180deg);
        transform: rotateY(-180deg);
    }

    .rightHandBottomContaer{
        width: 110px;
        height: 58px;
        position: absolute;
        z-dex: 1;
        : 81px;
        left: 248px;
        -webkit-transform-orig:  right;
        -webkit-transform: rotate(90deg);
        -moz-transform-orig:  right;
        -moz-transform: rotate(90deg);
        -o-transform-orig:  right;
        -o-transform: rotate(90deg);
        transform-orig:  right;
        transform: rotate(90deg);
        overflow: hidden;
    }

    .rightHandBottom{
        width: 68px;
        height: 28px;
        border: 1px solid #000;
        background: black;
        border-: none;
        position: absolute;
        : 1px;
        left: 38px;
        border-bottom-right-radius: 100% 40px;
        z-dex: 999;
    }

    .footWrapper{
        position: absolute;
        : 292px;
        left: 80px;
    }

    .leftFootTopWrapper {
        position: absolute;
        width: 130px;
        : 16px;
        left: -1px;
        height: 37px;
        overflow: hidden;
        z-dex: 2;
    }

    .leftFootTop{
        position: absolute;
        width: 120px;
        height: 60px;
        border: 4px solid black;
        background: #FF9C00;
        border--left-radius: 80% 70%;
        : -10px;
        left: 3px;
    }

    .toe {
        position: absolute;
        border-: 4px solid black;
        width: 25px;
        height: 20px;
        : 50px;
        left: 2px;
        border--right-radius: 30px 30px;
        border--left-radius: 10px 10px;
        -webkit-transform-orig:  left;
        -moz-transform-orig:  left;
        -o-transform-orig:  left;
        transform-orig:  left;
        z-dex: 10;
        -webkit-transform: rotate(-45deg);
        -moz-transform: rotate(-45deg);
        -o-transform: rotate(-45deg);
        transform: rotate(-45deg);
    }

    .toe.right{
        -webkit-transform: rotate(45deg) rotateY(180deg);
        -moz-transform: rotate(45deg) rotateY(180deg);
        -o-transform: rotate(45deg) rotateY(180deg);
        transform: rotate(45deg) rotateY(180deg);
        left: 264px;
    }

    .leftFootBottomWrapper {
        position: absolute;
        width: 130px;
        : 52px;
        left: -1px;
        height: 38px;
        overflow: hidden;
        z-dex: 2;
    }

    .leftFootBottom{
        position: absolute;
        width: 120px;
        height: 60px;
        border: 4px solid #000;
        background: #FF9C00;
        border--left-radius: 50% 44%;
        border--right-radius: 50% 44%;
        border-bottom-left-radius: 50% 56%;
        border-bottom-right-radius: 50% 56%;
        : -30px;
        left: 3px;
    }


    .rightFootTopWrapper {
        position: absolute;
        width: 134px;
        : 22px;
        left: 134px;
        height: 36px;
        overflow: hidden;
        z-dex: 2;
    }

    .rightFootTop{
        position: absolute;
        width: 120px;
        height: 60px;
        border: 4px solid black;
        background: #FF9C00;
        border--right-radius: 32% 65%;
        : 0px;
        left: 4px;
    }

    .rightFootBottomWrapper {
        position: absolute;
        width: 134px;
        : 52px;
        left: 134px;
        height: 38px;
        overflow: hidden;
    }

    .rightFootBottom{
        position: absolute;
        width: 120px;
        height: 60px;
        border: 4px solid #000;
        background: #FF9C00;
        border--left-radius: 50% 56%;
        border--right-radius: 50% 56%;
        border-bottom-left-radius: 50% 44%;
        border-bottom-right-radius: 50% 44%;
        : -30px;
        left: 3px;
    }

    .rightToe {
        position: absolute;
        width: 40px;
        height: 10px;
        border: 2px solid #000;
        background: #FF9C00;
        border-radius: 50%;
        -webkit-transform-orig: bottom right;
        -webkit-transform: rotate(34deg);
        -moz-transform-orig: bottom right;
        -moz-transform: rotate(34deg);
        -o-transform-orig: bottom right;
        -o-transform: rotate(34deg);
        transform-orig: bottom right;
        transform: rotate(34deg);
        : 35px;
        left: 210px;
        z-dex: 1;
    }

    .copyright{
        marg: 50px 0 0 0;
        height: 50px;
        color: #999;
        font-family: Tahoma;
        font-size: 12px;
        text-align: center;
    }

    .copyright a {
        color: #999;
        text-decoration: none;
    }

    .copyright a:hover, .copyright a:focus {
        outle: none;
        text-decoration: underle;
    }
</style>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by