纯CSS实现tooltip,css更改html标签的title样式

纯CSS实现tooltip,css更改html标签的title样式【笔者有时间会更新一些边界条件。目前的样式在极端情况是有问题的,请不要直接将代码copy到线上环境,这只是笔者写的一个小demo】

html代码:

以下代码直接可用,tootip的样式可以自己调试。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        span {
            position: relative;
            margin: 50px auto;
            border: 1px solid;
        }
        span[aria-label]:hover:after {
            content: attr(aria-label);
            position: absolute;
            bottom: -30px;
            left: 0;
            border: 1px solid;
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="box">
        <span aria-label="我是tooltip">我是主体内容啊</span>
    </div>
</body>
</html>
发布了293 篇原创文章 · 获赞 2381 · 访问量 314万+

猜你喜欢

转载自blog.csdn.net/weixin_43606158/article/details/104498266