CSS畫心形的三種方法,超級簡單
一、一顆div一顆心
用一個div畫出一個心,核心的方法就是使用偽元素
首先,我們在頁面上先寫出一個div
使用CSS,將這個div變為一個橘紅色的正方形:


接著我們利用元素的兩個偽元素:before和:after,畫出一個藍色的圓和一個黃色的圓,并且將它們的圓心分別定位在正方形的上邊和右邊,


再來,將剛剛實作的兩個圓變成和正方形一樣的顏色


最后,將元素div旋轉45度,我們要的心形就實作了!就是這么簡單


全部代碼如下,拿去跟女朋友表白吧
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
position: relative;
top: 100px;
left: 50%;
width: 100px;
height: 100px;
background-color: tomato;
}
div:before {
content: "";
position: absolute;
top: -50px;
left: 0;
width: 100px;
height: 100px;
border-radius: 50%;
background-color: blue;
}
div:after {
content: "";
position: absolute;
top: 0px;
left: 50px;
width: 100px;
height: 100px;
background-color: yellow;
border-radius: 50%;
}
div:before {
background-color: tomato;
}
div:after {
background-color: tomato;
}
div {
position: relative;
top: 100px;
left: 50%;
width: 100px;
height: 100px;
background-color: tomato;
transform: rotate(-45deg);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
二、一顆心不夠表達我的心意,那么就給她畫出一螢屏的心

浮動讓它們填滿整個螢屏

兩個偽元素代表我的左心房和右心房


讓左右心房都旋轉45度,就形成了我滿滿的一螢屏心

三、“以前我看事物,是用肉眼去看,但是在我死去的那一剎那,我開始用心眼去看這個世界,所有的事物,真的可以看得前所未有的那么清楚,” —周星馳

像素級的世界可以由box-shadow屬性實作

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/291243.html
標籤:其他
上一篇:C語言詳解:陣列
