:before伪类content实现垂直居中

编程知识 更新时间:2023-04-05 06:06:03

 

设置display: inline-block;的标签i与span标签一起会导致元素垂直不对齐,通过给i标签设置伪类before,content的不可为空,从而实现垂直居中。

 

 未设置伪类before

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .head-left .icon-wodeditu{
            background: #5daaff;
            width: 30px;
            height: 30px;
            border-radius: 100%;
            color: #fff;
            line-height: 30px;
            display: inline-block;
            text-align: center;
        }
        .head-left .icon-wodeditu:before{
            /*content: "111";*/
        }
         .head-left .title{
            color: #3c3d3f;
            margin: 0 10px;
            font-size: 16px;
        }
    </style>
</head>
<body>
<div class="head-left">
    <h2>
        <i class="icon-wodeditu"></i>
        <span class="title">我的可视化地图</span>
    </h2>

</div>
</body>
</html>

效果:

设置伪类before 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .head-left .icon-wodeditu{
            background: #5daaff;
            width: 30px;
            height: 30px;
            border-radius: 100%;
            color: #fff;
            line-height: 30px;
            display: inline-block;
            text-align: center;
        }
        .head-left .icon-wodeditu:before{
            content: "111";
        }
         .head-left .title{
            color: #3c3d3f;
            margin: 0 10px;
            font-size: 16px;
        }
    </style>
</head>
<body>
<div class="head-left">
    <h2>
        <i class="icon-wodeditu"></i>
        <span class="title">我的可视化地图</span>
    </h2>

</div>
</body>
</html>

效果:

更多推荐

:before伪类content实现垂直居中

本文发布于:2023-04-05 06:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/e4925df0efb4fc1c8acae0c4a1d015b8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 45177文章数
  • 14阅读数
  • 0评论数