Why “overflow: hidden” clears a float?
Because you establish a new Block Formatting Context when using overflow with anything ofther then visible (link to the w3.org specs).
Because you establish a new Block Formatting Context when using overflow with anything ofther then visible (link to the w3.org specs).
You can set the outerdiv‘s CSS to this #outerdiv { overflow: hidden; /* make sure this doesn’t cause unexpected behaviour */ } You can also do this by adding an element at the end with clear: both. This can be added normally, with JS (not a good solution) or with :after CSS pseudo element (not … Read more
You could put the two floated divs into another one that’s got “overflow: hidden” set: <div style=”overflow:hidden”> <div style=”float: left;”>Left</div> <div style=”float: right;”>Right</div> </div> <div style=”clear: both; margin-top: 200px;”>Main Data</div> edit — To add a bit to this 5-year-old answer: I think the cause of the confusing behavior is the somewhat complicated process of margin … Read more
Here’s the part of the linked answer that’s most relevant to your question: When you float a block element, you are telling the browser to position it next to the previous floated object, so long as the container is wide enough (otherwise it will drop below the previous object). As the author mentions this is … Read more
Use position:absolute; right: 0; No need for float:right with absolute positioning Also, make sure the parent element is set to position:relative;
You can use the clearfix to do “layout preserving” the same way overflow: hidden does. .clearfix:before, .clearfix:after { content: “.”; display: block; height: 0; overflow: hidden; } .clearfix:after { clear: both; } .clearfix { zoom: 1; } /* IE < 8 */ add class=”clearfix” class to the parent, and remove overflow: hidden;
This is an expected behavior of float positioning. When an element is floated to the left (in your case the .inline div), the following content flows down the right side of that element, line boxes get shortened BUT the width of the containing block which is established by the following element (in your case the … Read more
You can’t do this directly, because floats are aligned to the top: If there is a line box, the outer top of the floated box is aligned with the top of the current line box. The exact rules say (emphasis mine): A floating box’s outer top may not be higher than the top of its … Read more
If you wrapped your divs, like this: <div id=”main”> <div id=”sidebar”></div> <div id=”page-wrap”></div> </div> You could use this styling: #main { width: 800px; margin: 0 auto; } #sidebar { width: 200px; height: 400px; background: red; float: left; } #page-wrap { width: 600px; background: #ffffff; height: 400px; margin-left: 200px; } This is a slightly different look … Read more
Is this what you’re after? I changed your title into a h3 (header) tag, because it’s a more semantic choice than using a div. Live Demo #1 Live Demo #2 (with header at top, not sure if you wanted that) HTML: <div class=”post-container”> <div class=”post-thumb”><img src=”http://dummyimage.com/200×200/f0f/fff” /></div> <div class=”post-content”> <h3 class=”post-title”>Post title</h3> <p>post desc post … Read more