我想为我拥有的按钮做一个标签。我的问题是标签比按钮更宽。我现在是这样做的(简单的例子):
<div class="parent_container_the_icon">
<div class="label">
This is the label text
</div>
<div>CSS:
.parent_container_the_icon {
height: 50px;
width: 50px;
float: left;
}
.label {
display: block;
position: absolute;
white-space: nowrap;
}我想要的是标签采用标签文本本身的宽度,而不是对文本进行换行。目前,它不会对文本进行换行,但我得到了标签框中的文本溢出,因为该框只占用容器的最大宽度。
如何强制标签div适应文本的大小,而不继承父级的宽度?
发布于 2012-09-07 16:10:57
我想你已经得到你想要的了。也许可以签入另一个浏览器?
这是你的代码:jsfiddle
发布于 2012-09-07 15:59:32
HTML:
<div class="parent_container_the_icon">
<div class="label">
This it the label text
</div>
<div>CSS:
.parent_container_the_icon {
height: 50px;
min-width: 50px; /*<== changed width to min-width*/
float: left;
}
.label {
/*removed position:absolute*/
display: block;
white-space:nowrap;
}发布于 2014-05-05 18:49:10
您可以在父类中使用white-space: nowrap;属性,在子类中使用width: 100%;。
我希望这对你有用。
https://stackoverflow.com/questions/12313989
复制相似问题