Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active February 8, 2016 06:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoist/d7fe7f3b80ae94f6b988 to your computer and use it in GitHub Desktop.
Save egoist/d7fe7f3b80ae94f6b988 to your computer and use it in GitHub Desktop.
CSS 布局(非 flexbox 篇)

单栏

<div class="container">
  css is awesome!  
</div>
.container {
  /* 自适应宽度,最宽 800px  */
  max-width: 800px;
  /* 左右边距自适应以达到居中效果 */
  /* margin: 上 右 下 左 / 上下 左右 */
  margin: 0 auto;
}

双栏

http://jsbin.com/wupune/edit?html,css,output

<div class="container">
  <div class="left">
    left side!
  </div>
  <div class="main">
    main!
  </div>
</div>
.container {
  max-width: 800px;
  margin: 20px auto;
}
.main {
  margin-left: 270px;
  background-color: orange;
}
.left {
  width: 250px;
  float: left;
  background-color: gray;
}

三栏

中间主栏,两边是侧边栏(固定像素) http://jsbin.com/vegise/edit?html,css,output
中间主栏,两边是侧边栏(百分比) http://jsbin.com/reduje/edit?html,css,output

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