溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

css如何實(shí)現(xiàn)心形

發(fā)布時(shí)間:2021-07-23 16:58:59 來源:億速云 閱讀:247 作者:chen 欄目:web開發(fā)

這篇文章主要介紹“css如何實(shí)現(xiàn)心形”,在日常操作中,相信很多人在css如何實(shí)現(xiàn)心形問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”css如何實(shí)現(xiàn)心形”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

css實(shí)現(xiàn)心形的方法:首先利用“border-radius:100%”樣式畫兩個(gè)正圓;然后進(jìn)行定位,將兩個(gè)圓重合一部分;接著畫一個(gè)正方形,進(jìn)行定位,將正方形與兩個(gè)圓重合一部分,形成一個(gè)傾斜的心形;最后使用transform樣式調(diào)整愛心角度。

本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。

前期預(yù)備知識:

  • 明白正方形的畫法。

  • 明白圓形的畫法。

  • 明白什么是定位。

  • 明白怎么旋轉(zhuǎn)。

話不多說,先教大家怎么用css畫一個(gè)圓形。

.disc1{
    width: 100px;
    height: 100px;
    border:1px solid red;
    background-color: red;
    margin:300px 0px 0px 300px;
    border-radius:100%;
    float:left;
}

css如何實(shí)現(xiàn)心形

由于我們的愛心是由兩個(gè)圓和一個(gè)正方形組成的,所以我們還需要再來一個(gè)圓形。

.disc2{
    width: 100px;
    height: 100px;
    border:1px solid red;
    background-color: red;
    margin:250px 0px 0px 0px;
    border-radius:100%;
    float:left;
    position: relative;
    right: 50px;
}

css如何實(shí)現(xiàn)心形

第三步我們就需要做一個(gè)正方形了。

.square{
    width: 100px;
    height: 100px;
    border:1px solid red;
    background-color: red;
    margin: 300px 0px 0px 0px;
    float: left;
    position: relative;
    right: 152px;
}

css如何實(shí)現(xiàn)心形

做完這些的效果已經(jīng)基本上出來了,但是我們還需要調(diào)整一下愛心的角度,這時(shí)就需要用到我們css樣式中的transform中的rotate屬性了。

我們由于需要把三個(gè)div都旋轉(zhuǎn)角度,所以我們把這三個(gè)div放在一個(gè)div里面。具體代碼如下:

.main{
    transform: rotate(45deg);
    margin: 300px;
}

做到現(xiàn)在,我們的愛心就已經(jīng)做出來咯。效果圖如下:

css如何實(shí)現(xiàn)心形

全部代碼如下(包含HTML代碼和CSS代碼)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <style>
			*{
			    margin: 0px;
			    padding: 0px;
			}
			.main{
			    transform: rotate(45deg);
			    margin: 300px;
			}
			.disc1{
			    width: 100px;
			    height: 100px;
			    border:1px solid red;
			    background-color: red;
			    margin:300px 0px 0px 300px;
			    border-radius:100%;
			    float:left;
			}
			.disc2{
			    width: 100px;
			    height: 100px;
			    border:1px solid red;
			    background-color: red;
			    margin:250px 0px 0px 0px;
			    border-radius:100%;
			    float:left;
			    position: relative;
			    right: 50px;
			}
			.square{
			    width: 100px;
			    height: 100px;
			    border:1px solid red;
			    background-color: red;
			    margin: 300px 0px 0px 0px;
			    float: left;
			    position: relative;
			    right: 152px;
			}
		</style>
    </head>
    <body>
        <div class="main">
            <div class="disc1"></div>
            <div class="disc2"></div>
            <div class="square"></div>
        </div>
    </body>
</html>

到此,關(guān)于“css如何實(shí)現(xiàn)心形”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI