Aus*_*an 3 html css flexbox responsive-design
我创建了一个完整的网站,但删除了所有填充物并留下了 3 列 div。我的目标是在调整图像大小时让这 3 列垂直堆叠。
附加的 css 已包含在内,因为它与站点的其余部分一起使用,因此我将其全部包含在内。
我尝试查找某些媒体查询并尝试将头围绕在 flexbox 上。任何帮助,将不胜感激。
* {
border: 1px solid red;
/*For layout purposes only*/
}
* {
max-width: 980px;
font-family: 'Lato', sans-serif;
margin-left: auto;
margin-right: auto;
padding-bottom: 0px;
}
* {
box-sizing: border-box;
}
.container {
display: flex;
flex-wrap: wrap;
overflow: hidden;
}
.row {
width: 100%;
display: flex;
}
.img {
display: block;
margin: auto;
}
.col-1 {
width: 8.33%;
}
.col-2 {
width: 16.66%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.33%;
}
.col-5 {
width: 41.66%;
}
.col-6 {
width: 50%;
}
.col-7 {Run Code Online (Sandbox Code Playgroud)
<header class="container">
<div class="row">
<div class="col-4">
<img class="img" src="http://placehold.it/300x300">
</div>
<div class="col-4">
<img class="img" src="http://placehold.it/300x300">
</div>
<div class="col-4">
<img class="img" src="http://placehold.it/300x300">
</div>
</div>
</header>Run Code Online (Sandbox Code Playgroud)
弹性容器的初始设置是 flex-direction: row. 这意味着容器的子项(“弹性项目”)将水平对齐,就像在您的代码中一样。
要垂直堆叠项目,请切换到flex-direction: column。
.row {
display: flex;
flex-direction: column; /* NEW */
}
Run Code Online (Sandbox Code Playgroud)
如果您希望 flex 项目在调整大小时垂直堆叠,请flex-direction在媒体查询中更改:
@media screen and ( max-width: 500px ) {
.row { flex-direction: column; }
}
Run Code Online (Sandbox Code Playgroud)