![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f65584353526a794e59635a614435544c666e585569614343345656494c77785938786d484c44515a766a434e77666336495a5437395530716c376c6f75696353714173387a6c6b54766776686d48507448586566586634772f3634303f77785f666d743d706e67.webp)
寫在前面
今天這個練習,是我在國外的一個素材網站上看到的,我個人覺得很好玩,所以,我把這個源碼分享出來給大家,大家可以看一下最終的效果。
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f65584353526a794e5963595957793942664c6962543969636a39475830454c696179774a6d6f65503476716f6f6b5a674f7858303541367253495a6963504774707656776962644f5279363878555451394c7038766d594f356a772f3634303f77785f666d743d706e67.webp)
接下來,我們一起來看源碼吧。
HTML代碼:
<!DOCTYPE html><html><head><title>【每日一練】54—CSS實現的一個有趣的像素藝術畫</title></head><body> <div class="box"> <img src="monalisa.jpg"> </div> <div class="box pixel"> <img src="monalisa_pixel.jpg"> </div></body></html>*{ margin: 0; padding: 0; box-sizing: border-box;}body{ display: flex; justify-content: center; align-items: center; min-height: 100vh;}.box { position: relative; width: 400px; height: 600px; margin: 10px; background: #000;}.box img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;}.box.pixel img { image-rendering: pixelated; filter: contrast(1.4);}.box.pixel::before { content: ''; position: absolute; width: 100%; height: 100%; z-index: 1000; background: repeating-linear-gradient(0deg,#0006 0%, #0006 4%, transparent 4%, transparent 96%, #0006 96%, #0006 100%), repeating-linear-gradient(90deg,#0006 0%, #0006 4%, transparent 4%, transparent 96%, #0006 96%, #0006 100%); background-size: 10px 10px;}寫在最後
以上就是我今天跟你分享的練習內容,希望你會喜歡今天的【每日一練】,希望今天的小練習對你有用,如果你覺得有幫助的話,請點讚我,關注我,並將它分享給你身邊做開發的朋友,也許能夠幫助到他。
我是楊小愛,我們明天見。
學習更多技能
請點擊下方公眾號
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a2f7779696365386b46516866375772596a796e73444d6a52626743776961636b3445396e716f455262436d4469627352684570557135386f4b7749457963345675785647524f5153514c376c584972536f327972336e6f3149412f3634303f77785f666d743d676966.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6a70672f65584353526a794e59635a696348583247656961445837733664696364554a7677753569624c3972544e58696166626d6d494c436b686770437249474544675a666c3078535171444f76476e6963334141423150633559765a6b6e412f3634303f77785f666d743d6a706567.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f65584353526a794e59635a6457584d6e415073634842737337614a784874375371646962657532556e63434a43655056716a71724d6c684b4c4a37397768676a52554d754a7a69616a614b757a575a66776963546d505573672f3634303f77785f666d743d706e67.webp)