我有一个网页设计要求,要有这样的标题:
+-------------------------------------------------------------+
| +---------------------+ +-------++------------------------+|
| | float left DIV A | | DIV C || float right DIV B ||
| +---------------------+ +-------++------------------------+|
+-------------------------------------------------------------+
标题有 3 个部分:Div A、B、C。DIV A 向左浮动,而 DIV B 和 C 向右浮动。DIV A 和 DIV B 可能包含长文本。因此溢出的文本被截断为省略号。DIV C 有短文本,其内容不应被截断。
我试图使 HTML 如下所示:
<html>
<head>
<style>
.header
{
width: 100%;
border: 2px red;
overflow: hidden;
}
.DivA
{
float: left;
}
.DivC
{
float: right;
white-space:nowrap;
}
.DivB
{
float: right;
}
.clear
{
clear: both;
}
.DivA, .DivB
{
width: 40%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="header">
<div class="DivA">
Hello world 1 Hello world 2 Hello world 3
Hello world 1 Hello world 2 Hello world 3
Hello world 1 Hello world 2 Hello world 3
</div>
<div class="DivB">
Good bye Good bye
Good bye Good bye
Good bye Good bye
</div>
<div class="DivC">
No Ellipsis
</div>
<div class="clear">
</div>
</div>
</body>
</html>
text-overflow:ellipsis 仅在 DIV A 和 DIV B 具有宽度时才有效(在我的情况下,我将它们设置为 45%)。
但是,DIV C 存在一个问题。由于 DIV C 的宽度在不同的本地化中可能会有所不同,因此我们不能明确设置它的宽度。缩小浏览器窗口时,可以将 div C 换行到下一行。这看起来很糟糕。
有没有办法让DIV A和DIV B分别用溢出省略号向左和向右浮动,同时DIV C可以适应它的最佳宽度?