tags:

views:

936

answers:

3

I've got a fixed-width div with two buttons in it. If the labels of the buttons are too long, they wrap--one button stays on the first line, and the next button follows underneath it instead of adjacent to it.

How can I force the div to expand so that both buttons are on one line?

+2  A: 

Try white-space:nowrap;

Marek Karbarz
A: 

If your div has a fixed-width it shouldn't expand, because you've fixed its width. However, modern browsers support a min-width CSS property.

You can emulate the min-width property in old IE browsers by using CSS expressions or by using auto width and having a spacer object in the container. This solution isn't elegant but may do the trick:

<div id="container" style="float: left">
  <div id="spacer" style="height: 1px; width: 300px"></div>
  <button>Button 1 text</button>
  <button>Button 2 text</button>
</div>
Mr. Shiny and New
+1  A: 

If you don't care about a minimum width for the div and really just don't want the div to expand across the whole container, you can float it left -- floated divs by default expand to support their contents, like so:

<form>
    <div style="float: left; background-color: blue">
        <input type="button" name="blah" value="lots and lots of characters"/>
        <input type="button" name="blah2" value="some characters"/>
    </div>
</form>
Nicholas Becker