Div不会扩展到最大宽度 [英] Div does not expand to maximum width
问题描述
我有以下CSS类:
.CtractLabel
{
font-weight:bold;
padding: 2px;
text-align:left;
/* width:120px; */
width:150px;
float:left;
border-bottom:solid 1px #aaaaaa;
border-right:solid 1px #aaaaaa;
background: white url('../Images/GridHeaderBg.gif') repeat-x bottom;
}
在我的页面上,我有一个div,其文字小于150像素.但是,div不会扩展到150px,而是围绕文本收缩. 有没有一种方法可以将div精确地设置为150px,而不管div中文本的长度如何?
On my page, I have a a div with text that is less than 150px. However, the div does not expand to 150px, but contracts around the text. Is there a way to force the div to be precisely 150px regardless of the length of the text in the div?
推荐答案
div
元素的宽度的默认值为auto
,这将导致其水平占用所有可用空间.
The default value for the width of a div
element is auto
, which causes it to take up all available space horisontally.
如果您没有这种行为,则可能有一些原因:
If you don't get this behaviour, there are some possible causes:
- 您已将其设为浮动元素.
- 您已经以某种方式(可能是间接地)为其指定了宽度.
- 您还有其他占用空间的元素.
要确切了解CSS应用于元素的确切位置以及元素的确切位置,可以在Firefox中使用FireBug插件.
To see exactly what CSS applies to an element, and exactly where elements are, you can use the FireBug plugin in Firefox.
这篇关于Div不会扩展到最大宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!