使用 CSS3 和 HTML5 制作一个小黄人。

结构代码:

    <div class="wrap">
        <!-- 头发 -->
        <div class="hair">
            <div class="hair_1"></div>
            <div class="hair_2"></div>
        </div>
        <!-- 身体 -->
        <div class="body">
            <!-- 眼睛 -->
            <div class="eyes">
                <!-- 左眼 -->
                <div class="eyes_l">
                    <div class="l_black"></div>
                    <div class="l_white"></div>
                </div>
                <!-- 右眼 -->
                <div class="eyes_r">
                    <div class="r_black"></div>
                    <div class="r_white"></div>
                </div>
            </div>
            <!-- 嘴巴 -->
            <div class="mouth"></div>
            <!-- 裤子 -->
            <div class="trousers">
                <!-- 裤子上 -->
                <div class="trousers_t">
                    <div class="t_l_belt"></div>
                    <div class="t_r_belt"></div>
                </div>
                <!-- 裤子下 -->
                <div class="trousers_b"></div>
            </div>
        </div>

        <!-- 手臂 -->
        <div class="hand">
            <div class="hand_l"></div>
            <div class="hand_r"></div>
        </div>

        <!-- 腿脚 -->
        <div class="foot">
            <div class="foot_l"></div>
            <div class="foot_r"></div>
        </div>

    </div>

CSS 样式:

        .wrap {
            width400px;
            height600px;
            margin0 auto;
            border1px solid red;
            position: relative;
        }

        /*身体*/
        .body {
            width250px;
            height400px;
            border5px solid #000;
            border-radius125px;
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            background-color: yellow;
            overflow: hidden;

        }
        /*头发*/
        .hair_1,
        .hair_2 {
            width130px;
            height100px;
            border-top10px solid #000;
            border-radius:50%;
            position: absolute;
        }
        .hair_1 {
            left100px;
            top80px;
            transformrotate(45deg);
        }
        .hair_2 {
            left102px;
            top70px;
            transformrotate(50deg);
        }

        /*手臂*/
        .hand_l,
        .hand_r {
            width100px;
            height100px;
            border5px solid #000;
            position: absolute;
            border-radius30px;
            background-color: yellow;
            z-index: -1
        }
        .hand_l {
            left:50px;
            top:300px;
            transformrotate(30deg);
        }
        .hand_r {
            right:50px;
            top:300px;
            transformrotate(-30deg);
        }
        .hand_l::after,
        .hand_r::after {
            content"";
            width30px;
            height10px;
            position: absolute;
            background#000;
            border-radius:5px;

        }
        .hand_l::after {
            left6px;
            top60px;
            transformrotate(-90deg);
        }
        .hand_r::after {
            right6px;
            top:60px;
            transformrotate(-90deg);
        }

        /*腿*/

        .foot_l,
        .foot_r {
            width40px;
            height70px;
            background-color#000;
            position: absolute;
            top:490px;
            z-index: -1;
        }

        .foot_l {
            left:155px;

        }

        .foot_r {
            right:155px;

        }

        /*脚*/
        .foot_l::after,
        .foot_r::after {
            content"";
            width60px;
            height40px;
            background-color#000;
            border-radius20px;
            position: absolute;
            top30px;
        }

        .foot_l::after {
            left: -40px;
        }
        .foot_r::after {
            right: -40px;
        }

        /*眼睛*/
        .eyes{
            /*width: 100%;
            height: 100px;*/

            /*border: 1px solid red;*/
            position: absolute;
            top60px;
            left25px;
        }
        .eyes_l,
        .eyes_r {
            width90px;
            height90px;
            border5px solid #000;
            border-radius50%;
            background-color#fff;
            float: left;

        }
        .eyes_l::after,
        .eyes_r::after {
            content"";
            width31px;
            height20px;
            position: absolute;
            background-color#000;
            top35px;

        }

        .eyes_l::after {
            left: -26px;
            transformrotate(20deg);
            border-radius2px 7px 0px 2px;
        }
        .eyes_r::after {
            right: -26px;
            transformrotate(-20deg);
            border-radius8px 2px 0px 2px;
        }

        /*黑色眼珠*/
        .l_black,
        .r_black {
            width50px;
            height50px;
            background-color#000;
            border-radius50%;
            position: absolute;
            top23px;

        }
        .l_black {
            left25px;
        }
        .r_black {
            left125px;
        }
        /*白眼珠*/

        .l_white,
        .r_white {
            width20px;
            height20px;
            background-color#fff;
            border-radius50%;
            position: absolute;
            top40px;
        }
        .l_white {
            left50px;
        }
        .r_white {
            left130px;
        }

        /*嘴巴*/
        .mouth {
            width60px;
            height35px;
            border5px solid #000;
            border-radius0 0 0 30px;
            position: absolute;
            background-color#fff;
            left90px;
            top180px;
            transformrotate(-30deg);
        }
        .mouth::after {
            content"";
            width80px;
            height40px;
            background-color: yellow;
            position: absolute;
            border-bottom5px solid #000;
            left1px;
            top: -22px;
            transformrotate(30deg);
        }

        /*裤子上*/
        .trousers {
            width100%;
            height150px;

            position:absolute;
            top260px;

        }
        .trousers_t {
            width150px;
            height51px;
            background-color: blue;
            border5px solid #000;
            border-bottom: none;
            position: absolute;
            left45px;
            z-index10;

        }
        .trousers_b {
            width250px;
            height86px;
            background-color: blue;
            position: absolute;
            top50px;
            border-top5px solid #000;
            /*border-radius: 0 0 125px 125px;*/
        }

        /*肩带*/
        .t_l_belt,
        .t_r_belt {
            width100px;
            height20px;
            background-color: blue;
            border5px solid #000;
            position: absolute;
            top: -24px;

        }
        .t_l_belt {
            left:-74px;
            transformrotate(35deg);
        }
        .t_r_belt {
            right: -74px;
            transformrotate(-35deg);
        }

        .t_l_belt::after,
        .t_r_belt::after {
            content"";
            position: absolute;
            width10px;
            height10px;
            background-color#000;
            border-radius50%;
            top5px;
        }
        .t_l_belt::after{
            left87px;
        }
        .t_r_belt::after {
            left3px;
        }

        /*动画*/
        .hair_1,
        .hair_2 {
            animation: hair 5s ease-in infinite;
        }

        @keyframes hair {
            10% {
                transformrotate(45deg);
            }
            20% {
                transformrotate(56deg);
            }
            50% {
                transformrotate(45deg);
            }
            80% {
                transformrotate(56deg);
            }
            100% {
                transformrotate(45deg);
            }
        }

        .l_black,
        .r_black {
            animation: eye 5s linear infinite;
        }

        @keyframes eye {
            10% {
                transformtranslate(0);
            }
            20% {
                transformtranslate(20px);
            }
            50% {
                transformtranslate(0);
            }
            80% {
                transformtranslate(-20px);
            }
            100% {
                transformtranslate(0);
            }
        }

        .l_white,
        .r_white {
            animation: eyewhite 5s linear infinite;
        }

        @keyframes eyewhite {
            10% {
                transformtranslate(0,0);
            }
            20% {
                transformtranslate(20px,5px);
            }
            50% {
                transformtranslate(0,0);
            }
            80% {
                transformtranslate(-20px,5px);
            }
            100% {
                transformtranslate(0,0);
            }
        }

效果图:

posted on 2019-07-30 11:45  格物致知_Tony  阅读(420)  评论(0编辑  收藏  举报