-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[css] 第35天 使用flex实现三栏布局,两边固定,中间自适应 #129
Comments
这就是圣杯布局国内也叫双飞翼布局,在第一天已经有回答了 同意里面的一个回答,现在有很多简单的实现方式,传统的这个也是一种hack的方式,真的没必要去追究了,但是核心知识点可以掌握。 1.把 center 放在最前面,优先渲染 现在的flex/grid很轻松就能实现,甚至绝对定位也是很容易实现也更容易理解。 |
<div class="container">
<section class="left red"></section>
<section class="middle blue"></section>
<section class="right red"></section>
</div> .container {
width: 100%;
height: 100%;
display: flex;
}
.left,
.right {
flex: 0 0 auto;
width: 50px;
height: 100%;
}
.middle {
flex: 1 1 auto;
height: 100%;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
} |
.container {
display: flex;
height: 100px;
.left, .right {
width: 100px;
background: #8c939d;
}
.content {
flex: 1;
background: #306eff;
}
} |
添一句,如果是让中间的content在网页渲染的先渲染,需要把content写在第一个
因此需要给center left right增加一个order属性 |
中间不设置宽度,设置flex:1; |
|
中间不设置宽度,设置flex:1; |
弹性盒子中 flex: 0 1 auto 表示什么意思解释三个参数分别对应的是 flex-grow, flex-shrink 和 flex-basis,默认值为
三值语法三个值的含义:
|
<style type="text/css">
.wrap {
display: flex;
justify-content: space-between;
}
.left,right,.middle {
height: 100px;
}
.left {
width: 200px;
background: coral;
}
.right {
width: 120px;
background: lightblue;
}
.middle {
background: #555;
width: 100%;
margin: 0 20px;
}
</style>
|
第35天 使用flex实现三栏布局,两边固定,中间自适应
The text was updated successfully, but these errors were encountered: