花样鼠标悬停特效

发布于:2024-04-18 ⋅ 阅读:(32) ⋅ 点赞:(0)

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            width: 1000px;
            height: 580px;
            margin: 50px auto;
            border: 1px solid green;
            position: relative;
        }

        .top {
            margin: 0 auto 130px;
            padding: 10px 0;
            background: mediumpurple;
            color: #fff;
        }

        .fill:hover,
        .fill:focus {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            /* 2m=32px */
            box-shadow: inset 0 0 0 2em var(--hover);
        }

        .pulse:hover,
        .pulse:focus {
            animation: pulse 1s;
            box-shadow: 0 0 0 2em rgba(255, 255, 255, 0);
        }


        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 var(--hover);
            }
        }

        .close:hover,
        .close:focus {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            box-shadow: inset -3.5em 0 0 0 var(--hover), inset 3.5em 0 0 0 var(--hover);
        }

        .raise:hover,
        .raise:focus {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            box-shadow: 0 0.5em 0.5em -0.4em var(--hover);
            transform: translateY(-0.25em);
        }

        .up:hover,
        .up:focus {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            box-shadow: inset 0 -3.25em 0 0 var(--hover);
        }

        .slide:hover,
        .slide:focus {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            box-shadow: inset 6.5em 0 0 0 var(--hover);
        }

        .offset {
            /* box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>; */
            /* inset关键字是可选的,如果提供,阴影将在元素内部而不是外部。

            <offset-x>和<offset-y>定义阴影的水平和垂直偏移量。

            <blur-radius>是可选的,定义模糊距离。

            <spread-radius>也是可选的,定义阴影的大小。

            <color>定义阴影的颜色。 */
            box-shadow: 0.3em 0.3em 0 0 var(--color), inset 0.3em 0.3em 0 0 var(--color);
        }

        .offset:hover,
        .offset:focus {
            box-shadow: 0 0 0 0 var(--hover), inset 6em 3.5em 0 0 var(--hover);
        }

        .fill {
            --color: #a972cb;
            --hover: #cb72aa;
        }

        .pulse {
            --color: #ef6eae;
            --hover: #ef8f6e;
        }

        .close {
            --color: #ff7f82;
            --hover: #ffdc7f;
        }

        .raise {
            --color: #ffa260;
            --hover: #e5ff60;
        }

        .up {
            --color: #e4cb58;
            --hover: #94e458;
        }

        .slide {
            --color: #8fc866;
            --hover: #66c887;
        }

        .offset {
            --color: #19bc8b;
            --hover: #1973bc;
        }

        button {
            color: var(--color);
            transition: 0.25s;
        }

        button:hover,
        button:focus {
            border-color: var(--hover);
            color: #fff;
        }

        button {
            background: none;
            border: 2px solid;
            font: inherit;
            line-height: 1;
            margin: 0.5em;
            padding: 1em 2em;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="top">
            <h3>花样的鼠标悬停特效</h3>
        </div>
        <div style="width:640px ; margin:0 auto; background:#222222;">
            <button class="fill">Fill In</button>
            <button class="pulse">Pulse</button>
            <button class="close">Close</button>
            <button class="raise">Raise</button>
            <button class="up">Fill Up</button>
            <button class="slide">Slide</button>
            <button class="offset">Offset</button>
        </div>

    </div>
</body>

</html>