CSS3悬浮提示示例代码

最初发表于: 2019-10-21 19:01:13

示例代码如下

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            padding: 100px;
        }

        span {
            position: relative;
            display: inline-block;
        }

        span:hover {
            cursor: pointer;
        }

        span:hover:before {
            content: attr(data-tooltip);
            background: #d9444a;
            color: #fff;
            padding: .8em 1em;
            position: absolute;
            left: 100%;
            top: -70%;
            margin-left: 14px;
            white-space: pre;
        }

        span:hover:after {
            content: " ";
            position: absolute;
            left: 80%;
            width: 0;
            height: 0;
            border-right: 8px solid #d9444a;
            border-top: 8px solid transpatrnt;
            border-bottom: 8px solid transparent;
        }
    </style>
</head>

<body>
    <div>

        <span data-tooltip="hello world">Hover Me!!!</span>


    </div>

</body>

</html>