html5 - CSS div float left and right nowrap -
a little background: working on header spans entire on top of webpage. current username, logout button, etc. floated right in header, , logo , navitems on left. when browser window shrinks such left items , right items collide, not want them wrap. have header-container div set overflow: auto, start scrolling.
the question: when have div float:left , div float:right both display:inline-block, , parent white-space:no wrap - wrap!!! chance figured out work enclosing yet div display:inline-block. why this???
below code , working jsfiddle show both working setup, , setup wraps. don't understand why need div. http://jsfiddle.net/klyngbaek/tnhll/9/
when shrink window, not want second blue rectangle drop new line
html:
<h2>with inline-block dive. blue rectangles not wrap.</h2> <div class="wrapper nowrap"> <div class="second-wrapper"> <div class="floating float-left">[logo] | home | [navitem1] | [navitem2]</div> <div class="floating float-right">[username] | logout</div> </div> </div> <h2>without inline-block dive. blue rectangles wrap.</h2> <div class="wrapper nowrap"> <div class="floating float-left">[logo] | home | [navitem1] | [navitem2]</div> <div class="floating float-right">[username] | logout</div> <div class="clearfix"></div> </div>
css:
.wrapper { border:#333; margin-bottom:; } .second-wrapper { border:; display:inline-block; min-width: 100%; } .nowrap { white-space: nowrap; } .clearfix { clear: both; } .floating { background: lightblue; border:; height:; padding:} .float-left { float: left; } .float-right { float: right }
or perhaps there better way accomplish want.
thanks in advance!
edit: updated jsfiddle link
example left, right, top , bottom margins added; multiple divs; adjust height of main frame; set left margin left left floating div; , right margin of right floating div:
result:
styling , html in 1 file:
<html> <body> <style> .row { float:left; border: 3px solid blue; width: 96%; margin-left: 2%; margin-right: 2%; height: 115px; overflow: auto; position: static; } .floatleftdiv { display: inline-block; border: 3px solid red; width: 200px; height: 100px; margin-top: 3px; } .right { float: right; border: 3px solid red; width: 200px; height: 100px; margin-top: 3px; margin-right: 1%; } </style> <div class="row"> <div class="floatleftdiv" style="margin-left: 1%;">inline item a:</div> <div class="floatleftdiv">inline item b:</div> <div class="floatleftdiv">inline item c:</div> <div class="right">inline item d:</div> </div> </body> </html>
code modified discussion , one.
Comments
Post a Comment