Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Last active December 23, 2015 08:32
Show Gist options
  • Save khoand0000/8c2b6e3c7fdcebaa7e4f to your computer and use it in GitHub Desktop.
Save khoand0000/8c2b6e3c7fdcebaa7e4f to your computer and use it in GitHub Desktop.
2-columns or 3-columns layout css
  • Columns are calculated by percent (not pixel): using float and width: x% for each columns. It suits for columns
<div class="container">
  <div class="left">left</div>
  <div class="right">right</div>
  <div class="clear"></div>
</div>
.left {
  width: 30%;
  float: left;
}
.right {
  width: 70%;
  float: right;
}
.clear {
  clear: both;
}
  • Columns have fixed width (pixel), remaining column take remaining space: using margin-left or margin-right and position: absolute
<div class="container">
  <div class="left">left</div>
  <div class="right">right</div>
</div>
.container {
  position: relative;
}
.left {
  width: 300px;
  position: absolute;
}
.right {
  margin-left: 300px; // equal to width of .left
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment