我有以下html:
<div class="left">
this is left side. it should go to the bottom when in one column
</div>
<div class="right">
this is right side. it should go to the top when in one column
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.left {
width: 70%;
float: left;
background-color: red;
}
.right {
width: 30%;
float: left;
background-color: yellow;
}
@media only screen and (max-width : 768px) {
.left, .right {
width: 100%;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望当显示为一列时,使右列保持在顶部.
这是jsfiddle链接:https://jsfiddle.net/m7zpoc30/1/
请随时建议我应该做什么,包括改变我目前的CSS.
谢谢!
这是使用flex的解决方案,这可能是有意义的.您可以将左右div放入容器中display:flex,然后在调整大小时使用flex-direction.请参阅下面的代码段.(jsfiddle)
.container {
display: flex;
}
.left {
width: 70%;
background-color: red;
}
.right {
width: 30%;
background-color: yellow;
}
@media only screen and (max-width: 768px) {
.container {
flex-direction: column-reverse;
}
.left, .right {
width: 100%;
}
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="left">
this is left side. it should go to the bottom when in one column
</div>
<div class="right">
this is right side. it should go to the top when in one column
</div>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4188 次 |
| 最近记录: |