css h1 - only as wide as the text
Solution 1:
You can use the inline-block value for display, however in this case you will loose the block feature of h1 i.e. the siblings will be displayed inline with h1 if they are inline elements(in which case you can use a line-break
).
display:inline-block;
Solution 2:
.h1 {
width: -moz-fit-content;
width: fit-content;
// workaround for IE11
display: table;
}
All modern browsers support width: fit-content
for that.
For IE11 we could emulate this behavior with display: table
which doesn't break margin collapse like display: inline-block
or float: left
.