溫馨提示×

溫馨提示×

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

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

純CSS3如何制作的鼠標(biāo)懸停時邊框旋轉(zhuǎn)

發(fā)布時間:2021-06-18 10:26:38 來源:億速云 閱讀:114 作者:小新 欄目:web開發(fā)

這篇文章主要介紹純CSS3如何制作的鼠標(biāo)懸停時邊框旋轉(zhuǎn),文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

純CSS3實現(xiàn)的鼠標(biāo)懸停時邊框旋轉(zhuǎn)的效果:

純CSS3如何制作的鼠標(biāo)懸停時邊框旋轉(zhuǎn)

實現(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時的計算 */
        }
        .container {
            width: 100%;
            height: 100%;
            background: #0f0;
            text-align: center;
        }
        /* 設(shè)置content元素的屬性 */
        /* 此元素的寬和高必須相等,即設(shè)置border-radius: 50%;后應(yīng)該是一個圓 */
        /* 使用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è)置a的值為0即可隱藏 */
            border-radius: 50%;
            box-sizing: border-box;                     /* 使用此屬性防止邊框撐開盒子,border-box會讓邊框占用盒子里面的空間 */
            transition: all 2s;                          /* 該元素的所有屬性的變化會在2s內(nèi)完成 */
        }
        /* 使用偽類before設(shè)置需要轉(zhuǎn)動的邊框 */
        /* 因為如果元素邊框轉(zhuǎn)動,內(nèi)容也會跟著轉(zhuǎn)動 */
        /* 此處要的效果是只有邊框轉(zhuǎn)動而內(nèi)容不轉(zhuǎn)動 */
        .content:before {
            display: inline-block;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            box-sizing: border-box;
            content: '';
        }
        /* 設(shè)置鼠標(biāo)懸停在content元素上時content屬性的變化 */
        .content:hover {
            /*border: solid 15px rgba(255, 255, 255, 0);*/
        }
        /* 設(shè)置鼠標(biāo)懸停在content上時content的before偽類屬性的變化 */
        .content:hover:before {
            border: dashed 30px #fff;
            animation: whirl 9s linear infinite;  /* 執(zhí)行動畫whirl,執(zhí)行一次的周期是9s,執(zhí)行期間的速度曲線為linear,無限循環(huán) */
        }
        /* 設(shè)置文本內(nèi)容顯示的樣式 */
        .con-text {
            margin: -60% auto;
            width: 80%;
            font-size: 3rem;
            /* 以下三個屬性為了讓文字超出寬度時顯示省略號,必須同時使用才有效果 */
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
        /* 動畫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)懸停時邊框旋轉(zhuǎn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

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

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

AI