我需要一个标题和按钮在同一行,如果需要使用省略号.
@H_301_2@这是一个小提琴:http://jsfiddle.net/epyFT/1/
@H_301_2@我希望输出如下所示:
_________________________________________________________ | | | Header goes here [button] | | | ---------------------------------------------------------@H_301_2@要么
_________________________________________________________ | | | Super,super,super long header... [button] | | | ---------------------------------------------------------@H_301_2@或者一个较小的窗口:
____________________________ | | | Header goes... [button] | | | ----------------------------@H_301_2@该按钮不应该浮动到下一行.我该怎么做? @H_301_2@HTML
<div class="container"> <h2>This is the header that should never wrap and elipse if it doesn't fit</h2> <button>Button</button> </div> <div class="container"> <h2>Header</h2> <button>Button</button> </div>@H_301_2@CSS
.container { width:100%; } h2 { display:inline; min-width:200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; word-break: break-all; word-wrap: break-word; } button { width:100px; }@H_301_2@奖金 @H_301_2@获得第二个(固定宽度)按钮的额外功劳在那里向右拉.
_________________________________________________________ | | | Header goes here [button1] [button2] | | | | | | Super,super long... [button] [button2] | | | ---------------------------------------------------------
解决方法
也许这样的东西有帮助吗?
http://jsfiddle.net/epyFT/3/
@H_301_2@我不知道如何使按钮与容器的无卷宽度对齐,只使用单元格的百分比宽度.
@H_301_2@新代码:
<div class="container"> <div class="cell1"> <div class="wrap"> <h2>This is the header that should never wrap and elipse if it doesn't fit</h2> </div> </div> <div class="cell2"> <button>Button</button> </div> </div> <div class="container"> <h2>Header</h2> <button>Button</button> </div>@H_301_2@CSS:
.container { width:100%; display: table; table-layout: fixed; } .container > div { display: table-cell; } .cell1 { } .wrap { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; word-break: break-all; word-wrap: break-word; } .cell2 { width: 60%; } h2 { display:inline; min-width:200px; } button { width:100px; }