怎么使用純CSS實(shí)現(xiàn)一只紙鶴

這篇文章主要介紹了怎么使用純CSS實(shí)現(xiàn)一只紙鶴,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

站在用戶的角度思考問題,與客戶深入溝通,找到會寧網(wǎng)站設(shè)計(jì)與會寧網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋會寧地區(qū)。

效果預(yù)覽

怎么使用純CSS實(shí)現(xiàn)一只紙鶴

源代碼下載

https://github.com/comehope/front-end-daily-challenges

代碼解讀

定義 dom,容器中包含 6 個元素,分別代表頭、頸、身體側(cè)面、翅、尾、胸:

<div class="cranes">
    <span class="head"></span>
    <span class="neck"></span>
    <span class="side"></span>
    <span class="wing"></span>
    <span class="tail"></span>
    <span class="belly"></span>
</div>

居中顯示:

body {
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: dodgerblue;
}

定義容器尺寸:

.cranes {
    width: 52em;
    height: 50em;
    font-size: 7px;
}

設(shè)置紙鶴的顏色為白色:

.cranes {
    color: white;
}

畫出頭部:

.cranes {
    position: relative;
}

.head {
    border-left: 13em solid transparent;
    border-right: 6em solid transparent;
    border-bottom: 2em solid;
    position: absolute;
    left: 0;
    top: 21;
    transform: rotate(-5deg);
}

把以上創(chuàng)建三角形的代碼抽象成一個模板,然后數(shù)據(jù)都改為變量,類似于調(diào)用函數(shù)的樣子:

.cranes span {
    border-left: calc(var(--left) * 1em) solid transparent;
    border-right: calc(var(--right) * 1em) solid transparent;
    border-bottom: calc(var(--bottom) * 1em) solid;
    position: absolute;
    transform: rotate(calc(var(--rotation) * 1deg));
    left: calc(var(--x) * 1em);
    top: calc(var(--y) * 1em);
}

.head {
    --left: 13;
    --right: 6;
    --bottom: 2;    
    --x: 0;
    --y: 21;
    --rotation: -5;
}

設(shè)置透明度,以便元素疊加處有折紙效果:

.cranes span {
    filter: opacity(0.6);
}

接下來就是逐個調(diào)用生成三角形的函數(shù)創(chuàng)建其他三角形:

頸:

.neck {
    --left: 6;
    --right: 6;
    --bottom: 12;
    --x: 14;
    --y: 19;
    --rotation: 75;
}

身體側(cè)面:

.side {
    --left: 1.5;
    --right: 11.5;
    --bottom: 20;
    --x: 18.8;
    --y: 15.1;
    --rotation: 20;
}

翅:

.wing {
    --left: 18.7;
    --right: 30;
    --bottom: 8;
    --x: 6.7;
    --y: 9.2;
    --rotation: -41.9;
}

尾:

.tail {
    --left: 18.6;
    --right: 7.7;
    --bottom: 3.9;
    --x: 19.6;
    --y: 38.1;
    --rotation: -126.5;
}

胸:

.belly {
    --left: 6.2;
    --right: 1.8;
    --bottom: 11.5;
    --x: 17.5;
    --y: 27.8;
    --rotation: -99;
}

至此,紙鶴畫完。
最后,增加一點(diǎn)交互效果,當(dāng)鼠標(biāo)懸停時,由等腰直角三角形變形成鶴:

.cranes:hover span {
    animation: appear 1s ease-in;
}

@keyframes appear {
    from {
        border-left: 3em solid transparent;
        border-right: 3em solid transparent;
        border-bottom: 3em solid;
        position: absolute;
        transform: rotate(0deg);
        left: calc((52em - 3em) / 2);
        top: calc((50em - 3em) / 2);
    }
}

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享怎么使用純CSS實(shí)現(xiàn)一只紙鶴內(nèi)容對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!

網(wǎng)站欄目:怎么使用純CSS實(shí)現(xiàn)一只紙鶴
本文鏈接:http://muchs.cn/article4/jopsoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名移動網(wǎng)站建設(shè)、虛擬主機(jī)網(wǎng)站內(nèi)鏈、網(wǎng)站維護(hù)網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)