Why do “inline-block” elements in a “nowrap” div overflow?

前端 未结 4 1673
死守一世寂寞
死守一世寂寞 2021-01-11 11:32

The following code causes #headline to overflow #wrapper and I do not understand why this is happening.

HTML:

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 11:48

    Setting width to headline element fixes the issue.

    #headline {
       display: inline-block;
       vertical-align: middle;
       width: 60%;
    }
    

    It's responsive if both image wrapper and image have their max-width defined.

    #logo {
       display: inline-block;
       vertical-align: middle;
       max-width: 35%;
    }
    
    #logo img {
       width: 6em;
       max-width: 100%;
    }
    

    http://jsfiddle.net/tt1k2xmL/

提交回复
热议问题