我有两个按钮浮动到屏幕的两侧,如果屏幕缩小,我希望它们可以很好地折叠。在视觉上,这就是我想要的:
________________________________________________________________
| |
| |LongTextButtonName| |LongTextButtonName| | When the screen
|_______________________________________________________________| is large
_______________________________________
| |
| |LongTextBu...| |LongTextBu...| | When the screen is small
|______________________________________|
不幸的是,现在我明白了:
________________________________________
| |
| |LongTextButtonName| |
| |LongTextButtonName| |
|_______________________________________|
我想要一个仅限CSS的解决方案。
这是我当前的html和css(这里是fiddle):
<div class="button-container">
<div class="left-button"><a>LongTextButtonName</a></div>
<div class="right-button"><a>LongTextButtonName</a></div>
</div>
.button-container {
min-width:320px;
}
.button-container > div {
border: 1px solid gray;
background-color: orange;
min-width: 160px;
padding: 8px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.left-button {
float: left;
}
.right-button {
float: right;
}
答案 0 :(得分:12)
下面的小提琴基于以下内容:
box-sizing:border-box;
请注意,由于box-sizing:border-box;
,此解决方案无法在旧版浏览器上使用。
.button-container {
min-width:320px;
}
.button-container > div {
border: 1px solid gray;
background-color: orange;
max-width: 50%;
padding: 8px;
white-space: nowrap;
overflow: hidden;
box-sizing:border-box;
text-overflow: ellipsis;
}
.left-button {
float: left;
}
.right-button {
float: right;
}