Make Div as wide as it needs to be

后端 未结 5 579
我在风中等你
我在风中等你 2021-01-01 21:47

To explain my problem, I\'m trying to make a div wide enough to accommodate a dynamically generated title without wrapping it, but the div also has other content, which I wa

5条回答
  •  -上瘾入骨i
    2021-01-01 22:23

    Block elements such as divs extend as far as content pushes them, unless specified by explicit widths or heights.

    A pure CSS solution for this is unlikely without setting a max-width on the div.

    A pointer on CSS:

    • Don't include the tags in your selectors (i.e. tag.class) as you are then forced to use that tag with that class. Simply using .class will make it easier to change your markup (should you need to) as well as make your class extend its use to more than a single tag.

提交回复
热议问题