通过相对定位实现字穿线效果

主要思想两个盒子外面的盒子作为线 里面的盒子相对定位背景为白色加上padding即可

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .line {
            width: 500px;
            height: 1px;
            background-color: red;
            margin: 0 auto;
            text-align: center;
        }
        span {
            position: relative;
            top: -10px;
            padding: 10px;
            background-color: white;
        }
    </style>
</head>
<body>
    <div class="line">
        <span>今天是一个好日子因为天气很棒</span>
    </div>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/f2ehe/p/12045606.html