恐怕比那要复杂一些。
我需要一个流体宽度标题(h2),永远不会包装,与左对齐按钮(.btn1),所有没有重叠的固定宽度右按钮(.btn2)。
如果这听起来太复杂了,那么写得好的小提琴 (http://jsfiddle.net/8ZtU5/)和一些漂亮的ASCII艺术怎么样?
__________________________________________________
| |
| This header is really really... [One] [Two] |
| |
--------------------------------------------------
__________________________________________________
| |
| This header is short [One] [Two] |
| |
--------------------------------------------------
_________________________________
| |
| This header is... [One] [Two] |
| |
---------------------------------你认为如何?你能帮上忙吗?
HTML:(http://jsfiddle.net/8ZtU5/)
注意:额外的包装只是为了方便。除了呈现的结果之外,什么都不需要。
<div class="container">
<div class="fluid-width">
<div class="no-wrapping">
<h2>This header is really really really really really really really long</h2>
</div>
<button class="btn1">One</button>
</div>
<div class="fixed-width">
<button class="btn2">Two</button>
</div>
</div>
<div class="container">
<div class="fluid-width">
<div class="no-wrapping">
<h2>This header is short</h2>
</div>
<button class="btn1">One</button>
</div>
<div class="fixed-width">
<button class="btn2">Two</button>
</div>
</div>基本CSS:
.container {
margin:20px 0;
width:100%;
min-width:300px;
background:#eee;
}
.fluid-width {
min-width:200px;
display:inline-block;
}
.fixed-width {
width:100px;
max-width:100px;
min-width:100px;
display:inline-block;
}
.no-wrapping {
overflow: hidden; white-space: nowrap; text-overflow: ellipsis; word-break: break-all; word-wrap: break-word;
}
h2 {
display:inline;
}不用猜..。如果你想玩的话,那就全在小提琴上了:http://jsfiddle.net/8ZtU5/
发布于 2013-04-21 00:41:00
也许这就是你的意思。小提琴编辑了一下html structure
发布于 2013-04-21 01:00:34
这大致是一个解决方案,您可以通过更改h2的最大宽度来改变标题中显示的文本数量。
http://jsfiddle.net/QJg8X/
标记
<div class="container">
<div class="fluid-width">
<h2>This header is really really really really really really long</h2>
<button class="btn1">One</button>
<button class="btn2">Two</button>
</div>
</div>
<div class="container">
<div class="fixed-width">
<h2>This header is short</h2>
<button class="btn1">One</button>
<button class="btn2">Two</button>
</div>
</div>css
.container {
margin:20px 0;
width:100%;
min-width:300px;
background:#eee;
}
.fluid-width {
display: inline-block;
overflow: hidden;
min-width: 200px;
}
.fixed-width {
display: inline-block;
overflow: hidden;
width: 400px;
}
h2 {
float: left;
margin: 0;
padding: 0;
display: block;
white-space: nowrap;
max-width: 80%;
overflow: hidden;
text-overflow: ellipsis;
}
button.btn1 { float: left; }
button.btn2 { float: right; }不过,我只在现代浏览器上测试过上面的内容。
啊.。与AzDesign的答案非常相似(+1),但实际上它使用的是浮点数,而不是不确定的位置。
更新
另一种解决相同问题的方法是为按钮设置一个固定宽度区域,这意味着标记稍有改变,但意味着您不必指定最大宽度:
http://jsfiddle.net/QJg8X/2/
标记
<div class="container">
<div class="fluid-width">
<div class="buttons">
<button class="btn1">One</button>
<button class="btn2">Two</button>
</div>
<h2>This header is really really really really really really long</h2>
</div>
</div>
<div class="container">
<div class="fixed-width">
<div class="buttons">
<button class="btn1">One</button>
<button class="btn2">Two</button>
</div>
<h2>This header is short</h2>
</div>
</div>css
.container {
margin:20px 0;
width:100%;
min-width:300px;
background:#eee;
}
.fluid-width {
display: block;
overflow: hidden;
min-width: 200px;
}
.fixed-width {
display: block;
overflow: hidden;
width: 400px;
}
h2 {
margin: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.buttons {
display: block;
width: 150px;
float: right;
}
button.btn2 { float: right; }https://stackoverflow.com/questions/16126585
复制相似问题