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

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

Consider the following example: (live demo here)

HTML:



        
8条回答
  •  梦毁少年i
    2021-02-13 07:05

    You can use position:absolute; for this.

    For example:

    a {
        display: block;
        background: #000;
        line-height: 40px;
        height:80px;
        position:relative;  
    }
    
    img {
        position:absolute;
        top:50%;
        margin-top:-16px;
    }
    

    NOTE: This gives margin-top half of the image size.

    Check this http://jsfiddle.net/cXUnT/7/

提交回复
热议问题