下面以2017年新年祝福語為例給大家展示下效果。
純CSS3實(shí)現(xiàn)的鼠標(biāo)懸停時(shí)邊框旋轉(zhuǎn)的效果:
實(shí)現(xiàn)代碼如下,代碼中注釋已經(jīng)比較詳細(xì),就不再多說了:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> body { width: 40rem; height: 30rem; font-size: 62.50%; /* 把body的字體設(shè)置為10px以方便使用rem時(shí)的計(jì)算 */ } .container { width: 100%; height: 100%; background: #0f0; text-align: center; } /* 設(shè)置content元素的屬性 */ /* 此元素的寬和高必須相等,即設(shè)置border-radius: 50%;后應(yīng)該是一個(gè)圓 */ /* 使用rem相對于body的字體尺寸設(shè)置了寬和高 */ .content { display: inline-block; margin-top: 5rem; width: 20rem; height: 20rem; border: solid 15px rgba(255, 255, 255, 1); /* 此處設(shè)置邊框,使用rgba的方式是為了后面隱藏時(shí)方便,只需要設(shè)置a的值為0即可隱藏 */ border-radius: 50%; box-sizing: border-box; /* 使用此屬性防止邊框撐開盒子,border-box會(huì)讓邊框占用盒子里面的空間 */ transition: all 2s; /* 該元素的所有屬性的變化會(huì)在2s內(nèi)完成 */ } /* 使用偽類before設(shè)置需要轉(zhuǎn)動(dòng)的邊框 */ /* 因?yàn)槿绻剡吙蜣D(zhuǎn)動(dòng),內(nèi)容也會(huì)跟著轉(zhuǎn)動(dòng) */ /* 此處要的效果是只有邊框轉(zhuǎn)動(dòng)而內(nèi)容不轉(zhuǎn)動(dòng) */ .content:before { display: inline-block; width: 100%; height: 100%; border-radius: 50%; box-sizing: border-box; content: ''; } /* 設(shè)置鼠標(biāo)懸停在content元素上時(shí)content屬性的變化 */ .content:hover { /*border: solid 15px rgba(255, 255, 255, 0);*/ } /* 設(shè)置鼠標(biāo)懸停在content上時(shí)content的before偽類屬性的變化 */ .content:hover:before { border: dashed 30px #fff; animation: whirl 9s linear infinite; /* 執(zhí)行動(dòng)畫whirl,執(zhí)行一次的周期是9s,執(zhí)行期間的速度曲線為linear,無限循環(huán) */ } /* 設(shè)置文本內(nèi)容顯示的樣式 */ .con-text { margin: -60% auto; width: 80%; font-size: 3rem; /* 以下三個(gè)屬性為了讓文字超出寬度時(shí)顯示省略號,必須同時(shí)使用才有效果 */ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } /* 動(dòng)畫whirl,從0度旋轉(zhuǎn)到360度 */ @keyframes whirl { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } </style></head><body> <section class="container"> <div class="content" title="新年好新年好新年好"> <p class="con-text">新年好新年好新年好</p> </div> </section></body></html>
以上所述是小編給大家介紹的純CSS3制作的鼠標(biāo)懸停時(shí)邊框旋轉(zhuǎn),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選