Matthew905
Matthew905

Reputation: 1601

Css, How do I set the width of an container

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

Answers (3)

pat8719
pat8719

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

Fender
Fender

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

thirtydot
thirtydot

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.

http://jsfiddle.net/5jyAg/

Upvotes: 2

Related Questions