我正在尝试使用流体宽度创建内部div并在溢出时使用...
(使用ellipsis
)。
要求:
.container
已修复已知宽度200px
.badge
可以是任意宽度,但最大值为30px
。这是因为这个div包含一个数字(从0到999)。这必须保持right
(向右浮动)。.content
和.badge
必须在同一行.content
将有省略号和nowrap。必须留下left
.content
的宽度= .container
的宽度 - .badge
的宽度 我无法让#5
以上发生。任何指针?
下面的代码要么.badge
要换行第二行,要么.content
只是不扩展它的宽度。
HTML :
<div class=container>
<div class=content>
Donec id elit non mi porta gravida at eget metus
</div>
<div class=badge>
5
</div>
</div>
CSS :
.container {
width: 200px;
background: gray;
}
.content {
display: inline-block;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
max-width: 170px;
background: green;
}
.badge {
display: inline-block;
max-width: 30px;
background: yellow;
float: right;
}
答案 0 :(得分:2)
试试这个:
<div class=container>
<div class=badge>
5
</div>
<div class=content>
Donec id elit non mi porta gravida at eget metus
</div>
</div>
.container {
width: 200px;
background: gray;
}
.content {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
background: green;
}
.badge {
float:right;
max-width: 30px;
background: yellow;
}