You should be able to use floats without it messing up the layout, you just need to clear the floats properly.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
<style type="text/css" media="screen">
.container {
width: 100%;
overflow: hidden;
background: red;
}
.left, .right {
float: left;
width: 40%;
margin: 0 5%;
background: blue;
}
</style>
</head>
<body>
<div class="container">
<div class="left">yep</div>
<div class="right">yep</div>
</div>
</body>
</html>
display: table also works now and has good browser support.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
<style type="text/css" media="screen">
.container {
width: 100%;
display: table;
background: red;
border-spacing: 10px;
}
.left, .right {
display: table-cell;
width: 50%;
background: blue;
}
</style>
</head>
<body>
<div class="container">
<div class="left">yep</div>
<div class="right">yep</div>
</div>
</body>
</html>
But I always go for floats unless there's a reason to use tables for other reasons (equal height columns for example)
Bookmarks