css布局------左右宽度固定,中间宽度自适应容器

HTML

/*适用方法1,方法2*/
<body>
  <div class="container">
  <div class="left"></div>
  <div class="middle"></div>
  <div class="right"></div>
  </div>
</body>
/* 适用方法3:*/
<body>
  <div class="container">
  <div class="left"></div>
  <div class="right"></div>
  <div class="middle"></div>
  </div>
</body>

CSS

/*方法1:定位实现*/
.container {
position: relative;
}
.left {
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 100px;
background-color: red;
}
.middle {
box-sizing: border-box;
width: 100%;
height: 100px;
padding-left: 200px;
padding-right: 200px;
background-color: blue;
}
.right {
position: absolute;
top: 0;
right: 0;
width: 200px;
height: 100px;
background-color: red;
}
/*方法2:弹性布局实现*/
.container {
display: flex;
}
.left {
flex: 0 0 200px;
height: 100px;
background-color: red;
}
.middle {
width: 100%;
height: 100px;
background-color: blue;
}
.right {
flex: 0 0 200px;
height: 100px;
background-color: red;
}
/*方法3:浮动实现*/
.container {
overflow: hidden;
}
.left {
float: left;
width: 200px;
height: 100px;
background-color: red;
}
.middle {
box-sizing: border-box;
width: 100%;
height: 100px;
padding-left: 200px;
padding-right: 200px;
background-color: blue;
}
.right {
float: right;
width: 200px;
height: 100px;
background-color: red;
}
上一篇:Jmeter干货 不常用却极其有用的几个地方


下一篇:50% 的财富 500 强企业使用 Windows Azure