I have encountered a problem that can be best described with two images provided below.
Let's focus on the relevant CSS snippet:
h1 {
display: inline-block;
background-color: pink;
}
The first example shows an <h1>
tag with a short title that does not wrap. The background color of the tag only extends up to the width of the text it contains. This is the desired appearance for all titles.
In contrast, in the second image, the text has wrapped, causing the tag's width to be 100% of the container instead of just the text width itself. Even though the text almost fills the container, there is still some extra space present.
My main inquiry is understanding the mechanism behind this behavior. Does wrapped text always result in width: 100%;
? Are there any workarounds to avoid this limitation?
You can see the same issue demonstrated in this example fiddle.
Your insights are greatly appreciated. Thank you!