I have two buttons floating to opposite sides of the screen, and I'd like them to collapse nicely if the screen shrinks. Visually, this is what I want:
________________________________________________________________
| |
| |LongTextButtonName| |LongTextButtonName| | When the screen
|_______________________________________________________________| is large
_______________________________________
| |
| |LongTextBu...| |LongTextBu...| | When the screen is small
|______________________________________|
Unfortunately, right now I get this:
________________________________________
| |
| |LongTextButtonName| |
| |LongTextButtonName| |
|_______________________________________|
I'd like a css-only solution.
Here's my current html and css (and here's a 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;
}
The fiddle below works based on the following:
box-sizing:border-box;
Note that because of the box-sizing:border-box;
, this solution will not work on older browsers.
.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;
}
http://jsfiddle.net/UfxgZ/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With