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

前端 未结 30 4181
青春惊慌失措
青春惊慌失措 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:01

    display: inline-block adds an extra margin to your element.

    I would recommend this:

    #element {
        display: table; /* IE8+ and all other modern browsers */
    }
    

    Bonus: You can also now easily center that fancy new #element just by adding margin: 0 auto.

提交回复
热议问题