日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > HTML >内容正文

HTML

前端每日实战:142# 视频演示如何用 CSS 的 Grid 布局创作一枚小鸡邮票

發(fā)布時(shí)間:2024/4/17 HTML 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端每日实战:142# 视频演示如何用 CSS 的 Grid 布局创作一枚小鸡邮票 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

效果預(yù)覽

按下右側(cè)的“點(diǎn)擊預(yù)覽”按鈕可以在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。

https://codepen.io/comehope/pen/mGZbmQ

可交互視頻

此視頻是可以交互的,你可以隨時(shí)暫停視頻,編輯視頻中的代碼。

請(qǐng)用 chrome, safari, edge 打開(kāi)觀看。

https://scrimba.com/p/pEgDAM/cWMPaha

源代碼下載

每日前端實(shí)戰(zhàn)系列的全部源代碼請(qǐng)從 github 下載:

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

代碼解讀

定義 dom,容器表示郵票:

<div class="stamp"> </div>

居中顯示:

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

設(shè)置容器尺寸:

.stamp {position: relative;width: 57em;height: 71em;font-size: 5px;padding: 5em;background-color: white; }

用重復(fù)背景繪制出郵票的齒孔:

.stamp {display: flex;flex-direction: column;align-items: center;justify-content: center; }.stamp::after, .stamp::before {content: '';width: 100%;height: 100%;position: absolute;background: radial-gradient(circle, teal 50%, transparent 50%),radial-gradient(circle, teal 50%, transparent 50%);background-size: 3.5em 3.5em; }.stamp::before {top: 1.5em;background-repeat: repeat-y;background-position: -3% 0, 103% 0; }.stamp::after {left: 1.5em;background-repeat: repeat-x;background-position: 0 -2.5%, 0 102.5%; }

在 html 文件中增加小雞的 dom 元素,子元素分別表示頭部、喙、身體、尾巴、腿、爪子、太陽(yáng)、桔子:

<div class="stamp"><div class="rooster"><span class="head"></span><span class="beak"></span><span class="body"></span><span class="tail"></span><span class="leg"></span><span class="foot"></span><span class="sun"></span><span class="orange-stuff"></span></div> </div>

設(shè)置 grid 布局的行列尺寸:

.rooster {display: grid;grid-template-columns: 22.5em 13em 1.75em 14.5em 4.5em;grid-template-rows: 12.5em 14.5em 15em 8em 5.5em;background-color: wheat;padding: 2em;margin-top: -2em; }

畫(huà)出扇形的頭部:

.head {grid-column: 4;grid-row: 2;background-color: burlywood;border-top-left-radius: 100%; }

畫(huà)出小雞的眼睛和臉上的紅暈:

.head {position: relative; }.head::after {content: '';position: absolute;width: 2.8em;height: 2.8em;border-radius: 50%;background-color: black;right: 30%;box-shadow: 2em 4em 4em rgba(255, 100, 0, 0.5); }

畫(huà)出扇形的喙:

.beak {grid-column: 5;grid-row: 2;height: 4.5em;background-color: darkorange;border-bottom-right-radius: 100%; }

畫(huà)出半圓形的身體:

.body {grid-column: 2 / 5;grid-row: 3;width: 30em;background-color: saddlebrown;border-radius: 0 0 15em 15em; }

用偽元素,通過(guò)陰影畫(huà)出翅膀:

.body {position: relative;overflow: hidden; }.body::after {content: '';position: absolute;width: 20em;height: 10em;border-radius: inherit;box-shadow: 4em 2em 4em rgba(0, 0, 0, 0.3);left: calc((30em - 20em) / 2); }

畫(huà)出扇形的尾巴:

.tail {grid-column: 1;grid-row: 1 / 3;height: 22.5em;background-color: burlywood;align-self: end;border-top-left-radius: 100%; }

畫(huà)出扇形的腿:

.leg {grid-column: 4;grid-row: 4;width: 8em;background-color: burlywood;border-bottom-right-radius: 100%; }

畫(huà)出扇形的小爪子:

.foot {grid-column: 4;grid-row: 5;width: 5.5em;background-color: darkorange;border-top-right-radius: 100%; }

畫(huà)出半圓形的太陽(yáng):

.sun {grid-column: 3 / 5;grid-row: 1;width: 17em;--h: calc(17em / 2);height: var(--h);background-color: darkorange;border-radius: 0 0 var(--h) var(--h); }

畫(huà)出圓形的桔子和半圓形的葉片,注意此處葉片的畫(huà)法與前面畫(huà)半圓形的畫(huà)法不同:

.orange-stuff {grid-column: 1;grid-row: 3 / 6;width: 16em;height: 16em;background-color: darkorange;align-self: end;justify-self: end;border-radius: 50%;position: relative; }.orange-stuff::before {content: '';position: absolute;width: 8em;height: 8em;background: linear-gradient(45deg, transparent 50%, saddlebrown 50%);border-radius: 50%;top: -6.8em;left: 10%; }

在 dom 中再增加一些文本,包括標(biāo)題、作者和面值:

<div class="stamp"><div class="puppy"><!-- 略 --></div><p class="text"><span class="title">Rooster</span><span class="author">comehope</span><span class="face-value">120</span></p> </div>

設(shè)置標(biāo)題的文字樣式:

.text {position: relative;width: calc(100% + 2em * 2);height: 6em;font-family: sans-serif; }.text .title {position: absolute;font-size: 6em;font-weight: bold;color: brown; }

設(shè)置作者的文字樣式:

.text .author {position: absolute;font-size: 3em;bottom: -1.2em;color: dimgray; }

設(shè)置面值的文字樣式:

.text .face-value {position: absolute;font-size: 14em;right: 0;line-height: 0.9em;color: darkcyan; }

大功告成!

總結(jié)

以上是生活随笔為你收集整理的前端每日实战:142# 视频演示如何用 CSS 的 Grid 布局创作一枚小鸡邮票的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。