CSS可以幫助我們制作一些有趣的圖形效果,比如圣誕圖。下面是我分享的一些CSS代碼,讓你可以創(chuàng)建自己的圣誕圖。
/*用CSS制作一個(gè)圣誕樹*/ .tree { position: relative; width: 100px; height: 155px; margin: 100px auto 0; } .tree:before { content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid green; } .tree:after { content: ""; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 30px; height: 25px; background: brown; border-radius: 0 0 5px 5px; } .tree span { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 70px; height: 70px; background: brown; border-radius: 50%; } .tree .ornament1 { position: absolute; top: 55px; left: 45px; width: 10px; height: 10px; background: red; border-radius: 50%; } .tree .ornament2 { position: absolute; top: 70px; left: 60px; width: 10px; height: 10px; background: red; border-radius: 50%; } .tree .ornament3 { position: absolute; top: 75px; left: 30px; width: 10px; height: 10px; background: red; border-radius: 50%; } .tree .ornament4 { position: absolute; top: 85px; left: 50px; width: 10px; height: 10px; background: red; border-radius: 50%; } .tree .ornament5 { position: absolute; top: 100px; left: 40px; width: 10px; height: 10px; background: red; border-radius: 50%; } .tree .star { position: absolute; top: 30px; left: 50%; transform: translate(-50%, -50%); width: 15px; height: 15px; background: yellow; clip-path: polygon(50% 0%, 63% 38%, 100% 38%, 69% 59%, 82% 100%, 50% 75%, 18% 100%, 31% 59%, 0% 38%, 37% 38%); } /*在HTML中調(diào)用*/
上面的代碼中,我們用CSS制作了一個(gè)圣誕樹,并往樹上掛了些小裝飾。你也可以改變這些樣式,創(chuàng)建符合你自己想法的圣誕圖。
希望這些CSS代碼能幫助你為你的網(wǎng)站增添一些節(jié)日氣氛哦!