-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day160:动手实现一个左右固定100px,中间自适应的三列布局?(至少三种) #974
Comments
1、
2、
3、
|
1.float
|
整体的html <div class="container">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div> 方法1: flex.container {
display: flex;
height: 100px;
}
.container * {
height: 100px;
}
.left,
.right {
flex-basis: 100px;
background-color: aquamarine;
}
.center {
flex-grow: 1;
background: red;
} 方法2: position.container {
height: 100px;
position: relative;
}
.container * {
height: 100px;
position: absolute;
top: 0;
}
.left,
.right {
background-color: aquamarine;
width: 100px;
}
.left {
left: 0;
}
.right {
right: 0;
}
.center {
background: red;
left: 100px;
right: 100px;
} 方法3:float+margin如果用浮动的话,html布局要稍微调整一下 <div class="container">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div> css如下 .container {
height: 100px;
overflow: hidden;
}
.container * {
height: 100px;
}
.left,
.right {
background-color: aquamarine;
width: 100px;
}
.left {
float: left;
}
.right {
float: right;
}
.center {
background: red;
margin: 0 100px;
} 方法4:grid.container {
height: 100px;
overflow: hidden;
display: grid;
grid-template-columns: 100px auto 100px;
}
.container * {
height: 100px;
}
.left,
.right {
background-color: aquamarine;
width: 100px;
}
.center {
background: red;
} 但grid布局兼容性不太友好,参考caniuse |
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
The text was updated successfully, but these errors were encountered: