CSS: Why “vertical-align: middle” does not work?

前端 未结 8 1068
无人及你
无人及你 2021-02-13 06:24

Consider the following example: (live demo here)

HTML:



        
8条回答
  •  别跟我提以往
    2021-02-13 06:57

    I can't really tell you the specifics as to why this happens (I'm curious myself). But this works for me:

    a {
        display: block;
        background: #000;
        line-height: 40px;  
    }
    img {
        vertical-align: middle;
        margin-top:-4px; /* this work for me with any given line-height or img height */
    }
    

提交回复
热议问题