【发布时间】:2016-11-17 09:03:06
【问题描述】:
基于this post,我尝试让左边的 div 填满剩余空间,左右应该始终在一行中,右边的 div 应该完全可见。
如何做到这一点?
#left {
width: 100%;
background-color: #ff0000;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
float: left;
}
#right {
float: right;
background-color: #00FF00;
}
<body>
<div>
<div id="left">
left text should have the remaining width and shortended if it is too long lorem ipsum minion dolor
</div>
<div id="right">
this text is dynamic - should be fully visibile
</div>
</div>
</body>
编辑:
Flex-box 答案不起作用。如果绿色文字变短,看起来是这样的:
我想要的是绿色 div 现在变小,当文本很短时。
【问题讨论】:
-
你想要两个 div 在一行吗?为什么左 div 上没有浮动?
-
是的,完全是...向左添加浮动,没有帮助