Skip to content

Instantly share code, notes, and snippets.

@jakejscott
Created January 17, 2012 13:35
Show Gist options
  • Select an option

  • Save jakejscott/1626646 to your computer and use it in GitHub Desktop.

Select an option

Save jakejscott/1626646 to your computer and use it in GitHub Desktop.
940px wide 4 column grid using negative margins
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="wrapper">
<div class="clearfix">
Before Grid
</div>
<div class="grid">
<div class="row clearfix">
<div class="col">col 1</div>
<div class="col">col 2</div>
<div class="col">col 3</div>
<div class="col">col 4</div>
</div>
<div class="row clearfix">
<div class="col">col 1</div>
<div class="col">col 2</div>
<div class="col">col 3</div>
<div class="col">col 4</div>
</div>
</div>
<div class="clearfix">
After Grid
</div>
</div>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#wrapper {
width: 940px;
background: #ccc;
margin: 0 auto;
}
.grid {
float: left;
margin-left: 20px;
}
.row {
width: 960px;
margin-left: -20px;
}
.col {
margin-right: 20px;
width: 220px;
float: left;
background: orangered;
}
.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }
</style>
</body>
</html>
@jakejscott
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment