感谢阅读本文 · 欢迎在下方留言交流你的想法
探索更多文章 →左右定宽,中间自适应,利用负边距来改变文档流
![]()
html<div class="content"> <div class="middle"></div> <div class="left"></div> <div class="right"></div> </div>
css.content { overflow: hidden; padding: 0 100px; } .middle { position: relative; width: 100%; float: left; height: 80px; background: #f00; } .left { position: relative; width: 100px; float: left; left: -100px; height: 80px; margin-left: -100%; background: #0f0; } .right { position: relative; width: 100px; float: left; right: -100px; height: 80px; margin-left: -100px; background: #00f; }
html<div class="content"> <div class="middle"> <div class="inner-middle"></div> </div> <div class="left"></div> <div class="right"></div> </div>
css
.content {
overflow: hidden;
}
.middle {
width: 100%;
float: left;
}
.inner-middle{
width:100%;
height: 80px;
background: green;
}
.left {
width: 100px;
float: left;
height: 80px;
margin-left: -100%;
background: yellow;
}
.right {
width: 100px;
float: left;
height: 80px;
margin-left: -100px;
background: pink
}