用CSS 来画奇形怪状的图

2023-04-05  本文已影响0人  Messix_1102
<!DOCTYPE html>
<html lang="en">

<head>
    <style type="text/css">
        #square {
            width: 100px;
            height: 100px;
            background: red;
        }

        #rectangle {
            width: 200px;
            height: 100px;
            background: red;
        }

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

        #oval {
            width: 200px;
            height: 100px;
            background: red;
            border-radius: 100px / 50px;
        }

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

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

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

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

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

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

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

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

        #curvedarrow {
            position: relative;
            width: 0;
            height: 0;
            border-top: 9px solid transparent;
            border-right: 9px solid red;
            -webkit-transform: rotate(10deg);
            -moz-transform: rotate(10deg);
            -ms-transform: rotate(10deg);
            -o-transform: rotate(10deg);
        }

        #curvedarrow:after {
            content: "";
            position: absolute;
            border: 0 solid transparent;
            border-top: 3px solid red;
            border-radius: 20px 0 0 0;
            top: -12px;
            left: -9px;
            width: 12px;
            height: 12px;
            -webkit-transform: rotate(45deg);
            -moz-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            /*ie浏览器兼容*/
            -o-transform: rotate(45deg);
            /*opear浏览器兼容*/
        }

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

        #parallelogram {
            width: 150px;
            height: 100px;
            -webkit-transform: skew(20deg);
            -moz-transform: skew(20deg);
            -o-transform: skew(20deg);
            background: red;
        }

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

        #star-six {
            width: 0;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-bottom: 100px solid red;
            position: relative;
        }

        #star-six:after {
            width: 0;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-top: 100px solid red;
            position: absolute;
            content: "";
            top: 30px;
            left: -50px;
        }

        #star-five {
            margin: 50px 0;
            position: relative;
            display: block;
            color: red;
            width: 0px;
            height: 0px;
            border-right: 100px solid transparent;
            border-bottom: 70px solid red;
            border-left: 100px solid transparent;
            -moz-transform: rotate(35deg);
            -webkit-transform: rotate(35deg);
            -ms-transform: rotate(35deg);
            -o-transform: rotate(35deg);
        }

        #star-five:before {
            border-bottom: 80px solid red;
            border-left: 30px solid transparent;
            border-right: 30px solid transparent;
            position: absolute;
            height: 0;
            width: 0;
            top: -45px;
            left: -65px;
            display: block;
            content: '';
            -webkit-transform: rotate(-35deg);
            -moz-transform: rotate(-35deg);
            -ms-transform: rotate(-35deg);
            -o-transform: rotate(-35deg);
        }

        #star-five:after {
            position: absolute;
            display: block;
            color: red;
            top: 3px;
            left: -105px;
            width: 0px;
            height: 0px;
            border-right: 100px solid transparent;
            border-bottom: 70px solid red;
            border-left: 100px solid transparent;
            -webkit-transform: rotate(-70deg);
            -moz-transform: rotate(-70deg);
            -ms-transform: rotate(-70deg);
            -o-transform: rotate(-70deg);
            content: '';
        }

        #pentagon {
            position: relative;
            width: 54px;
            border-width: 50px 18px 0;
            border-style: solid;
            border-color: red transparent;
        }

        #pentagon:before {
            content: "";
            position: absolute;
            height: 0;
            width: 0;
            top: -85px;
            left: -18px;
            border-width: 0 45px 35px;
            border-style: solid;
            border-color: transparent transparent red;
        }

        #hexagon {
            width: 100px;
            height: 55px;
            background: red;
            position: relative;
        }

        #hexagon:before {
            content: "";
            position: absolute;
            top: -25px;
            left: 0;
            width: 0;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-bottom: 25px solid red;
        }

        #hexagon:after {
            content: "";
            position: absolute;
            bottom: -25px;
            left: 0;
            width: 0;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-top: 25px solid red;
        }

        #octagon {
            width: 100px;
            height: 100px;
            background: red;
            position: relative;
        }

        #octagon:before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            border-bottom: 29px solid red;
            border-left: 29px solid #eee;
            border-right: 29px solid #eee;
            width: 42px;
            height: 0;
        }

        #octagon:after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            border-top: 29px solid red;
            border-left: 29px solid #eee;
            border-right: 29px solid #eee;
            width: 42px;
            height: 0;
        }

        #heart {
            position: relative;
            width: 100px;
            height: 90px;
        }

        #heart:before,
        #heart:after {
            position: absolute;
            content: "";
            left: 50px;
            top: 0;
            width: 50px;
            height: 80px;
            background: red;
            -moz-border-radius: 50px 50px 0 0;
            border-radius: 50px 50px 0 0;
            -webkit-transform: rotate(-45deg);
            -moz-transform: rotate(-45deg);
            -ms-transform: rotate(-45deg);
            -o-transform: rotate(-45deg);
            transform: rotate(-45deg);
            -webkit-transform-origin: 0 100%;
            -moz-transform-origin: 0 100%;
            -ms-transform-origin: 0 100%;
            -o-transform-origin: 0 100%;
            transform-origin: 0 100%;
        }

        #heart:after {
            left: 0;
            -webkit-transform: rotate(45deg);
            -moz-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            -o-transform: rotate(45deg);
            transform: rotate(45deg);
            -webkit-transform-origin: 100% 100%;
            -moz-transform-origin: 100% 100%;
            -ms-transform-origin: 100% 100%;
            -o-transform-origin: 100% 100%;
            transform-origin: 100% 100%;
        }

        #badge-ribbon {
            position: relative;
            background: red;
            height: 100px;
            width: 100px;
            -moz-border-radius: 50px;
            -webkit-border-radius: 50px;
            border-radius: 50px;
        }

        #badge-ribbon:before,
        #badge-ribbon:after {
            content: '';
            position: absolute;
            border-bottom: 70px solid red;
            border-left: 40px solid transparent;
            border-right: 40px solid transparent;
            top: 70px;
            left: -10px;
            -webkit-transform: rotate(-140deg);
            -moz-transform: rotate(-140deg);
            -ms-transform: rotate(-140deg);
            -o-transform: rotate(-140deg);
        }

        #badge-ribbon:after {
            left: auto;
            right: -10px;
            -webkit-transform: rotate(140deg);
            -moz-transform: rotate(140deg);
            -ms-transform: rotate(140deg);
            -o-transform: rotate(140deg);
        }

        div{
            margin-top:200px;
        }
    </style>
</head>

<body>
    <div id="square"></div>
    <div id="rectangle"></div>
    <div id="circle"></div>
    <div id="oval"></div>
    <div id="triangle-up"></div>
    <div id="triangle-down"></div>
    <div id="triangle-left"></div>
    <div id="triangle-right"></div>
    <div id="triangle-topleft"></div>
    <div id="triangle-topright"></div>
    <div id="triangle-bottomleft"></div>
    <div id="triangle-bottomright"></div>
    <div id="curvedarrow"></div>
    <div id="trapezoid"></div>
    <div id="parallelogram"></div>
    <div id="star-six"></div>
    <div id="star-five"></div>
    <div id="pentagon"></div>
    <div id="hexagon"></div>
    <div id="octagon"></div>
    <div id="heart"></div>
    <div id="badge-ribbon"></div>
</body>

</html>


<!-- 
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
-->
上一篇下一篇

猜你喜欢

热点阅读