开发者

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 con开发者_如何学编程tainer?

Thanks for your help, -Matthew


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/


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


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜