I’m trying to keep the bar_top_container div from wrapping it’s contents no matter how wide the page is (i.e. both selects should appear always on the same line), this is not working however when the page width is to small for them to both fit on one line, how can i fix this?
Styles:
#bar_top_container { position: relative; white-space: nowrap; }
#bar_top_block { float: left; padding-left: 10px; padding-right: 10px; border-right: 1px solid #4965BB; }
#clear { clear: both; }
HTML:
<div id="bar_top_container">
<div id="bar_top_block">
<span class="bold">select1: </span>
<select><option value="asdf">asdf</option></select>
</div>
<div id="bar_top_block">
<span class="bold">asdf: </span>
<select><option value="blah">-- select action --</option></select>
</div>
<div id="clear"></div>
</div>
You can have both
blockandinlineproperties for an element if you display it as …inline-block!Here is your code corrected and working:
span.bold are
labelsa
labelis associated to itsformelement via thefor/idattributesbar_top_blockis anidused twice. Should be aclassno need for
float: left;asdisplay: inline-block;is usedthus no need for a clearing element either
the
.bar_top_blockelements are also displayed inline so any whitespace between them is displayed as whitespace. To avoid this, I added a comment that avoid any whitespace though still letting the HTML code readable. The text within is ‘no whitespace‘ so the developer will know that this comment is there for a reason and shouldn’t be stripped 🙂you can remove the
widthonbody, it’s just here for the exampleyou can play with the
overflowproperty on the containeras IE7 and below don’t understand the
inline-blockvalue on block elements like div, you must usedisplay: inlineand give the element the hasLayout with, for example,zoom: 1;the best way to target IE7 and below and only those browsers is with a conditional comment
I added support for Fx2 but this is merely for historical reasons 🙂
.