Flexbox 弹性方向问题
Flexbox flex-direction issue
我对 flexbox 有疑问。所以我里面有 1 个容器和 2 个块。当屏幕宽度小于 700px 时,我想将 flex-direction 设置为 "column"。但我不能。当屏幕宽度小于 700px 时,none 个不显示。 :)
index.html
<html>
<head>
<title>Flexbox</title>
</head>
<body>
<div class = "container">
<div class = "slot_1"></div>
<div class = "slot_2"></div>
</div>
<style>
*{
margin: 0 auto;
padding: 0 ;
}
.container{
width:100%;
height:100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.slot_1{
background:red;
flex: 3;
}
.slot_2{
background:orange;
flex:1;
}
@media (max-width:700px){
.content{
flex-direction: column;
}
}
</style>
</body>
这里有几个问题:
.content
应该是 .container
.
- 您应该为
.slot_1
和 .slot_2
指定宽度。
工作正常CSS
*{
margin: 0 auto;
padding: 0 ;
}
.container{
width:100%;
height:100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.slot_1{
height: 30px;
background:red;
flex: 3;
}
.slot_2{
height: 30px;
background:orange;
flex:1;
}
@media all and (max-width: 700px){
.container{
flex-direction: column;
}
.slot_1,
.slot_2 {
width:100%;
}
}
为了演示,我添加了 30px 的高度。
这里也正在 fiddle 使用您的示例:
https://jsfiddle.net/x5h1ohzr/
你在媒体查询中的class名字是错误的。是.content
,不应该是.container
吗?
我对 flexbox 有疑问。所以我里面有 1 个容器和 2 个块。当屏幕宽度小于 700px 时,我想将 flex-direction 设置为 "column"。但我不能。当屏幕宽度小于 700px 时,none 个不显示。 :)
index.html
<html>
<head>
<title>Flexbox</title>
</head>
<body>
<div class = "container">
<div class = "slot_1"></div>
<div class = "slot_2"></div>
</div>
<style>
*{
margin: 0 auto;
padding: 0 ;
}
.container{
width:100%;
height:100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.slot_1{
background:red;
flex: 3;
}
.slot_2{
background:orange;
flex:1;
}
@media (max-width:700px){
.content{
flex-direction: column;
}
}
</style>
</body>
这里有几个问题:
.content
应该是.container
.- 您应该为
.slot_1
和.slot_2
指定宽度。
工作正常CSS
*{
margin: 0 auto;
padding: 0 ;
}
.container{
width:100%;
height:100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.slot_1{
height: 30px;
background:red;
flex: 3;
}
.slot_2{
height: 30px;
background:orange;
flex:1;
}
@media all and (max-width: 700px){
.container{
flex-direction: column;
}
.slot_1,
.slot_2 {
width:100%;
}
}
为了演示,我添加了 30px 的高度。
这里也正在 fiddle 使用您的示例: https://jsfiddle.net/x5h1ohzr/
你在媒体查询中的class名字是错误的。是.content
,不应该是.container
吗?