My goal is to have an h3
element take up only the space as the text inside it. I am unable to use span
directly for this purpose. Even encapsulating the h3
element with a span
did not yield the desired outcome. The red color should stretch horizontally only as wide as the text 'hello world'.
The HTML code looks like this:
<div class="parent">
<h3 class="center">hello world</h3>
</div>
And here's the accompanying CSS code:
.parent {
padding-left:5px;
overflow:auto;
background-color:blue;
}
.center {
text-align:center;
overflow:auto;
background-color:red;
}
Check out the result on JSFiddle.