Div Size Automatically size of content

前端 未结 7 701
萌比男神i
萌比男神i 2021-02-03 17:07

I am trying to make a h2 header for sidebar widgets but I want the width of the div class to be whatever width the content becomes. It seems I can\'t just set a width because th

相关标签:
7条回答
  • 2021-02-03 17:24

    As far as I know, display: inline-block is what you probably need. That will make it seem like it's sort of inline but still allow you to use things like margins and such.

    0 讨论(0)
  • 2021-02-03 17:29

    The easiest is:

    width: fit-content;

    0 讨论(0)
  • 2021-02-03 17:31

    If display: inline; isn't working, try out display: inline-block;. :)

    0 讨论(0)
  • 2021-02-03 17:32

    h2 { display: inline }

    0 讨论(0)
  • 2021-02-03 17:35

    The best way to do this is to set display: inline;. Note, however, that in inline display, you lose access to some layout properties, such as manual height and vertical margins, but this doesn't appear to be a problem for your page.

    0 讨论(0)
  • 2021-02-03 17:38

    I faced the same issue and I resolved it by using: max-width: fit-content;

    0 讨论(0)
提交回复
热议问题