如何使用CSS的Grid佈局實現小雞郵票(附代碼)
這篇文章帶給大家的內容是關於如何使用CSS的Grid佈局實現小雞郵票(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
效果預覽

原始碼下載
https://github.com/comehope/front-end-daily-challenges
#程式碼解讀
定義dom,容器表示郵票:
<div> </div>
居中顯示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: teal; }
設定容器尺寸:
.stamp { position: relative; width: 57em; height: 71em; font-size: 5px; padding: 5em; background-color: white; }
用重複背景繪製出郵票的齒孔:
.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 元素,子元素分別表示頭部、喙、身體、尾巴、腿、爪子、太陽、桔子:
<div> <div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div> </div>
設定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; }
畫出扇形的頭部:
.head { grid-column: 4; grid-row: 2; background-color: burlywood; border-top-left-radius: 100%; }
畫出小雞的眼睛和臉上的紅暈:
.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); }
畫出扇形的喙:
.beak { grid-column: 5; grid-row: 2; height: 4.5em; background-color: darkorange; border-bottom-right-radius: 100%; }
畫出半圓形的身體:
.body { grid-column: 2 / 5; grid-row: 3; width: 30em; background-color: saddlebrown; border-radius: 0 0 15em 15em; }
用偽元素,透過陰影畫出翅膀:
.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); }
畫出扇形的尾巴:
.tail { grid-column: 1; grid-row: 1 / 3; height: 22.5em; background-color: burlywood; align-self: end; border-top-left-radius: 100%; }
畫出扇形的腿:
.leg { grid-column: 4; grid-row: 4; width: 8em; background-color: burlywood; border-bottom-right-radius: 100%; }
畫出扇形的小爪子:
.foot { grid-column: 4; grid-row: 5; width: 5.5em; background-color: darkorange; border-top-right-radius: 100%; }
畫出半圓形的太陽:
.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); }
畫出圓形的桔子和半圓形的葉片,注意此處葉片的畫法與前面畫半圓形的畫法不同:
.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 中再增加一些文本,包括標題、作者和麵值:
<div> <div> <!-- 略 --> </div> <p> <span>Rooster</span> <span>comehope</span> <span>120</span> </p> </div>
設定標題的文字樣式:
.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; }
設定作者的文字樣式:
.text .author { position: absolute; font-size: 3em; bottom: -1.2em; color: dimgray; }
設定面值的文字樣式:
.text .face-value { position: absolute; font-size: 14em; right: 0; line-height: 0.9em; color: darkcyan; }
大功告成!
以上是如何使用CSS的Grid佈局實現小雞郵票(附代碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

在 Bootstrap 中插入圖片有以下幾種方法:直接插入圖片,使用 HTML 的 img 標籤。使用 Bootstrap 圖像組件,可以提供響應式圖片和更多樣式。設置圖片大小,使用 img-fluid 類可以使圖片自適應。設置邊框,使用 img-bordered 類。設置圓角,使用 img-rounded 類。設置陰影,使用 shadow 類。調整圖片大小和位置,使用 CSS 樣式。使用背景圖片,使用 background-image CSS 屬性。

要調整 Bootstrap 中元素大小,可以使用尺寸類,具體包括:調整寬度:.col-、.w-、.mw-調整高度:.h-、.min-h-、.max-h-

如何使用 Bootstrap 按鈕?引入 Bootstrap CSS創建按鈕元素並添加 Bootstrap 按鈕類添加按鈕文本

要設置 Bootstrap 框架,需要按照以下步驟:1. 通過 CDN 引用 Bootstrap 文件;2. 下載文件並將其託管在自己的服務器上;3. 在 HTML 中包含 Bootstrap 文件;4. 根據需要編譯 Sass/Less;5. 導入定製文件(可選)。設置完成後,即可使用 Bootstrap 的網格系統、組件和样式創建響應式網站和應用程序。

創建 Bootstrap 分割線有兩種方法:使用 標籤,可創建水平分割線。使用 CSS border 屬性,可創建自定義樣式的分割線。

HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。

答案:可以使用 Bootstrap 的日期選擇器組件在頁面中查看日期。步驟:引入 Bootstrap 框架。在 HTML 中創建日期選擇器輸入框。 Bootstrap 將自動為選擇器添加樣式。使用 JavaScript 獲取選定的日期。

在 Vue.js 中使用 Bootstrap 分為五個步驟:安裝 Bootstrap。在 main.js 中導入 Bootstrap。直接在模板中使用 Bootstrap 組件。可選:自定義樣式。可選:使用插件。
