Reputation: 1601
Css question here: How do I set the width of a container just wide enough for how many characters are in the container?
Thanks for your help, -Matthew
Upvotes: 0
Views: 146
Reputation: 1700
You can try to put and even Padding into your style. For example if your markup looks like this.
<div>
<p class="paddThis">Your text</p>
</div>
and in your style sheet set the padding of the right and/or left of the text your text will push the left and right border of your container a certain amount of pixels away from you text creating which should accomplish what you are trying to do.
Your style sheet might look like this
.paddThis
{
padding: 0 5px 0 5px;
}
Upvotes: 0
Reputation: 3055
it depends on the container, if you use a span
as the container, it will always be as wide as the characters in it.
but a span is inline element
Upvotes: 1
Reputation: 228292
display: inline-block
is an easy way to do this.
float: left
is another option.
Make sure an explicit width
is not being set, because that will disable the shrink-wrap behaviour.
Upvotes: 2