三栏布局实现方式

1.float+margin

<div class="wrapper">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
</div>

.left {
    float: left;
    width: 300px;
    height: 400px;
    background-color: limegreen;
 
}
 
.right {
    float: right;
    width: 200px;
    height: 400px;
    background-color: yellowgreen;
}
 
.center {
    height: 400px;
    margin: 0 200px 0 300px;
    background-color: tomato;
}

2.flex

<div class="wrapper">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>
div {
  display: flex;
}
.left{
  width: 100px;
  height: 100px;
  border: 1px solid #55FFFF;
}
.center{
  flex: 1;
  border: 1px solid #55FFFF;
}
.right{
  width: 100px;
  height: 100px;
  border: 1px solid #55FFFF;
} 

3.position

<div class="wrapper">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>
.wrapper {
    position: relative;
}
 
.left {
    position: absolute;
    left: 0;
    top: 0;
    width: 300px;
    height: 500px;
    background-color: lightgreen;
}
 
.right {
    position: absolute;
    right: 0;
    top: 0;
    width: 200px;
    height: 500px;
    background-color: lightskyblue;
}
 
.center {
    height: 500px;
    margin: 0 200px 0 300px;
    background-color: tomato;
}

4.grid

<div class="wrapper">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>
.wrapper {
  display: grid;
  grid-template-columns: 100px auto 100px;
  grid-column-gap: 10px;
}

5.双飞翼布局

<div class="wrapper">
  <div class="center-wrapper">
    <div class="center">所有人都在努力,并不是只有你满腹委屈</div>
  </div>
  <div class="left">只要在变好,慢一点也无妨</div>
  <div class="right">如果你真的不在乎,又怎么会有那么多情绪</div>
</div>
*{
  margin: 0;
  padding: 0;
}
.wrapper{
  height: 100px;
}
.center-wrapper,
  .left,
  .right{
  float: left;
  height: 100px;
}
.center-wrapper{
  width: 100%;
  background-color: #32CD32;
}
.left{
  width: 100px;
  margin-left: -100%;
  background-color: #55FFFF;
}
.right{
  width: 100px;
  margin-left: -100px;
  background-color: #800080;
}
.center {
  margin-left: 100px;
  margin-right: 100px;
  height: 500px;
}

6.圣杯布局

<div class="wrapper">
    <div class="center"></div>
    <div class="left"></div>
    <div class="right"></div>
</div>
.wrapper {
    height: 500px;
    padding: 0 200px 0 300px; /* wrapper的container两侧空出来left和right的宽度 */
}
 
.center, .left, .right {
    position: relative;
    float: left;
}
 
.center {
    width: 100%; /* 宽度=wrapper的container的宽度,两侧已空出left和right */
    height: 500px;
    background-color: tomato;
}
 
.left {
    width: 300px;
    height: 500px;
    margin-left: -100%; /* 左侧紧邻container左侧 */
    left: -300px; /* 移至左侧紧邻wrapper最左侧,右侧紧邻container左侧 */
    background-color: lightgreen;
}
 
.right {
    width: 200px;
    height: 500px;
    margin-left: -200px; /* 右侧紧邻container右侧 */
    right: -200px; /* 移至右侧紧邻wrapper最右侧 */
    background-color: lightskyblue;
}
 
posted @ 2021-08-10 19:40  .爬行的蜗牛  阅读(30)  评论(0编辑  收藏  举报
Document