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

前端 未结 4 1692
死守一世寂寞
死守一世寂寞 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 12:10

    This content wrap because of white-space: normal;.

    The white-space CSS property determines how whitespace inside an element is handled. To make words break within themselves, use overflow-wrap, word-break, or hyphens instead. Now there if you want to limit this with #wrapper than you can limit the overflow property for the div.If you using white-space: nowrap; for div this clear the overflow text and show the div in a single line (ROW).

    #wrapper {
        background: #fea;
        width: 50%;
        overflow: hidden;
    }
    
    #logo {
        display: inline-block;
        vertical-align: middle;
    }
    
    #logo img {
           width: 6em; 
    }
    
    #headline {
         display: inline-block;
         vertical-align: middle;
    
    
    }
    

提交回复
热议问题