<div class="first"></div>
<div class="second"></div>
Run Code Online (Sandbox Code Playgroud)
我试着用CSS这样做对其进行更改float:left与float:right和下扭转它@media (max-width:820px),我相信在过去的工作,但没有工作的查询.
尝试了一个简单的JQuery:
if ($(window).width() < 820) {
$( ".first" ).insertAfter( $( ".second" ) );
}
else {
$( ".first" ).insertBefore( $( ".second" ) );
}
Run Code Online (Sandbox Code Playgroud)
我知道这应该是如此简单,但它不是在打球,我做错了什么?
您是否尝试过Flexbox订购?
.container {
display: flex;
}
.container > div {
display: block;
padding: 1em 0;
flex: 1;
background-color: red;
}
@media (max-width: 800px) {
.first {
order: 2;
}
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="first">first</div>
<div class="second">second</div>
</div>Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/xgkpfgc5/1/