How to vertically align both text and image middle of div?

This question already has an answer here:

  • Vertically align text next to an image? 20 answers

  • 你可以在你的#titleimage span添加vertical-align:middle

    #titleimage{
        background: red;
        display: inline-block;
    }
    #titleimage a{
        text-decoration: none;
    }
    #titleimage img{
        width: 33px;
        height: 36px;
        vertical-align: middle;
    }
    #titleimage span{
        color: white;
        font-family: sans-serif;
        font-size: 26px;
        vertical-align:middle;
        }
    

    只需将vertical-align添加到您的span标签。

     #titleimage span{
            color: white;
            font-family: sans-serif;
            font-size: 26px;
            vertical-align:middle;/*add this*/
        }
    

    Add #titleimage span { vertical-align: middle; } #titleimage span { vertical-align: middle; } and remove #titleimage img { vertical-align: middle; } #titleimage img { vertical-align: middle; }

    链接地址: http://www.djcxy.com/p/41538.html

    上一篇: 需要跨越图像中间,但不工作

    下一篇: 如何垂直对齐文本和图像中间的div?