2015-04-05 68 views
2

我正在使用两个部门(两个高度设置为自动)。重新排序Div像源重新排序

现在,在移动视图中,我希望左侧视图为100%宽度,底部和右侧视图为100%并位于顶部;怎么能做到这一点?

如果我将margin-left:100%设置为左侧而margin-left:-100% to right则设置为离屏,水平滚动条显示在浏览器中。

这里是 FIDDLE

Image showing current, and desired, outcome

+0

您是否尝试过使用'位置:relative'? – 2015-04-05 02:49:50

+0

不,不工作.. – 2015-04-05 02:53:29

+0

仍然divs与右侧水平滚动条 – 2015-04-05 02:53:43

回答

1

下面是使用完全相同的HTML的例子。只有CSS正在改变,这可以通过媒体查询完成。

html, body{ height:100%; width:100%; margin:0; padding:0 } 
 

 
#red{ 
 
    background:red; height:40%; width:50%; float:left; 
 
} 
 

 
#yellow{ 
 
    background:yellow; height:40%; width:50%; float:left; 
 
}
<div id="yellow"></div><div id="red"></div>

html, body{ height:100%; width:100%; margin:0; padding:0 } 
 

 
#red{ 
 
    background:red; height:40%; width:100%; 
 
} 
 

 
#yellow{ 
 
    background:yellow; height:40%; width:100%; 
 
}
<div id="yellow"></div><div id="red"></div>

编辑:使用,如果你希望它们翻转下面的代码。

html, body{ height:100%; width:100%; margin:0; padding:0 } 
 

 
#red{ 
 
    background:red; height:40%; width:100%; 
 
    position:relative; 
 
    top:-40%; 
 
} 
 

 
#yellow{ 
 
    background:yellow; height:40%; width:100%; 
 
    position:relative; 
 
    top:40%; 
 
}
<div id="yellow"></div><div id="red"></div>

+0

怎么办,如果我在顶部,左边底部 – 2015-04-05 02:58:04

+0

我更新了我的答案。让我知道这是否适合你。 – 2015-04-05 03:04:09

+0

谢谢,但如果它的响应和我不知道高度。我的意思是它的自动高度就像在框架中一样? – 2015-04-05 03:11:50