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
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.
The easiest is:
width: fit-content;
If display: inline;
isn't working, try out display: inline-block;
. :)
h2 { display: inline }
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.
I faced the same issue and I resolved it by using: max-width: fit-content;