Like the others, I would use float: left
, but you need to clear the parent div too like in this working jsFiddle demo.
HTML:
<div class="clearfix">
<div class="floatLeft">
<div>Topic</div>
<div>Sub Topic</div>
</div>
<div class="floatLeft">
<div>test 1</div>
<div>Test 2</div>
</div>
</div>
Hello
CSS:
div {
margin: 10px;
padding: 10px;
border: dotted 1px black;
}
.floatLeft { float: left; }
/* The Magnificent Clearfix:
Updated to prevent margin-collapsing on child elements.
j.mp/bestclearfix */
.clearfix:before, .clearfix:after {
content: "\0020";
display: block;
height: 0;
overflow: hidden;
}
.clearfix:after { clear: both; }
/* Fix clearfix:
blueprintcss.lighthouseapp.com/projects/15318/tickets/5-extra-margin-padding-bottom-of-page */
.clearfix { zoom: 1; }