How can I make a div not larger than its contents?

前端 未结 30 3619
青春惊慌失措
青春惊慌失措 2020-11-21 07:35

I have a layout similar to:

I would like for the div to only exp

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 08:12

    You can use inline-block as @user473598, but beware of older browsers..

    /* Your're working with */
    display: inline-block;
    
    /* For IE 7 */
    zoom: 1;
    *display: inline;
    
    /* For Mozilla Firefox < 3.0 */
    display:-moz-inline-stack;
    

    Mozilla doesn’t support inline-block at all, but they have -moz-inline-stack which is about the same

    Some cross-browser around inline-block display attribute: https://css-tricks.com/snippets/css/cross-browser-inline-block/

    You can see some tests with this attribute in: https://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/

提交回复
热议问题