Css繪畫豬頭

效果圖.png

參考文章:http://www.javanx.cn/20190102/2019-css-pig/
‘豬’,代表著聚財(cái)福氣,豬年即將到來,祝大家‘豬’事順利,我屬豬,你嘞(斜眼笑)
html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>豬豬</title>
        <link rel="stylesheet" type="text/css" href="./css/test.css">
    </head>
    <body>
        <div class="pig">
            <div class="body">
                <div class="ear"></div>
                <div class="eye">
                    <div class="left-eye"></div>
                    <div class="right-eye"></div>
                </div>
                <div class="nose"></div>
            </div>
            <div class="foot">
                <div class="left-foot"></div>
                <div class="right-foot"></div>
            </div>
        </div>
    </body>
</html>

scss

* {
    padding: 0;
    margin: 0;
}
@mixin ear {
    content: '';
    display: inline-block;
    width: 50px;
    height: 50px;
    background: #db7452;
    border-radius: 50% 0;
    box-shadow: 1px 1px 4px #8c2d1b;
}
@mixin eye($width,$height,$marginL) {
    position: relative;
    content: '';
    display: inline-block;
    margin-left: $marginL;
    width: $width;
    height: $height;
}
@mixin nose($left) {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d27658;
    position: relative;
    left: $left;
}
@mixin foot($deg) {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-width: 5px 15px 8px 5px;
    border-color: transparent #f3ad8f transparent transparent;
    border-style: solid;
    transform: rotate($deg);
}
.pig {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    // 身體就是個橢圓
    .body {
        width: 200px;
        height: 150px;
        border: 1px solid #f3ad8f;
        border-radius: 120px 120px 100px 100px;
        background-color: #f3ad8f;
        position: relative;
        // 耳朵也是在圓形的基礎(chǔ)上進(jìn)行變形
        .ear {
            width: 100%;
            height: 50px;
            position: absolute;
            top: -10px;
            &::before {
                @include ear;
                margin-left: 20px;
            }
            &::after {
                @include ear;
                float: right;
                transform: rotateY(180deg);
                margin-right: 20px;
            }
        }
        // 眼睛是由一個三角和橢圓拼接而成
        .eye {
            width: 100%;
            height: 20px;
            margin-top: 60px;
            > div {
                width: 48%;
                height: 100%;
                text-align: center;
                display: inline-block;
                &::before {
                    @include eye(0px,0px,8px);
                    left: -5px;
                    top: -1px;
                    border-width: 4px;
                    border-style: solid;
                    border-color: transparent #000 transparent transparent;
                }
                &::after {
                    @include eye(5px,10px,-5px);
                    background: #000;
                    border-radius: 0 10px 10px 0;
                }
            }
        }
        // 鼻子是由一個橢圓和兩個圓拼接而成
        .nose {
            width: 60px;
            height: 30px;
            background: #da938f;
            border-radius: 20px;
            position: relative;
            left: 50%;
            transform: translateX(-50%);
            text-align: center;
            &::before {
                @include nose(-10px);
            }
            &::after {
                @include nose(10px);
            }
        }
    }
    // 腳是由兩個三角形拼接而成
    .foot {
        width: 200px;
        height: 20px;
        margin-top: -10px;
        .left-foot {
            float: left;
            margin-left: 20px;
            transform: rotate(20deg);
            &::before {
                @include foot($deg:-80deg);
            }
            &::after {
                @include foot($deg:-100deg);
                margin-left: -10px;
            }
        }
        .right-foot {
            float: right;
            margin-right: 20px;
            transform: rotate(-20deg);
            &::before {
                @include foot($deg:-80deg);
            }
            &::after {
                @include foot($deg:-100deg);
                margin-left: -10px;
            }
        }
    }
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前端的小伙伴們有福利啦?。?! 什么?聽說!css樣式還可以被編譯執(zhí)行了。學(xué)過前端的小伙伴都知道,css樣式...
    家娃閱讀 15,680評論 2 6
  • 編寫css是前端工作中,一項(xiàng)普通而又頻繁的勞動,由于css并不是一門語言,所以在程序設(shè)計(jì)上顯得有些簡陋。對于小型項(xiàng)...
    Jack_Lo閱讀 5,864評論 15 39
  • Netflix Logo In CSS 這篇博客是Gregor Adams關(guān)于他如何設(shè)法如何用CSS重現(xiàn)Netfl...
    MakingChoice閱讀 1,421評論 0 1
  • 如果時間退到2年前,那么CSS預(yù)處理是非?;鸬? CSS預(yù)處理器: 基于CSS的另一種語言.通過工具譯成CSS添加...
    這個超人不會飛阿閱讀 833評論 0 3
  • 刻意練習(xí)訓(xùn)練營感想(4) 一、 參加了四周的刻意練習(xí),要結(jié)營了。呵呵,堅(jiān)持這么長時間先給自己...
    老男孩兒組閱讀 239評論 0 0

友情鏈接更多精彩內(nèi)容