css - 响应式网页设计 float 位置

标签 css responsive-design

我试图在两列 float css 设计中实现以下目标

enter image description here

我的两个 css 是这样的:

.div1 {
 width: 25%;
 float:left;
}

.div2 {
 width: 75%;
 float: right;
}

.container {
 width:960px;
}

@media screen and (max-width: 320px) {
 .div1, .div2 {
 width: 100%;
 display: block;
 float: none;
 clear: both;
 }
 .container {
  width: 100%;
 }
}

我的 html 是这样的:

...
<div class="container">
 <div class="div1">
 ... content inside
 </div>
 <div class="div2">
  <img src="photo_loc"/>
 </div>
</div>

我有 Div I 和 Div II。 Div I 的宽度为 25%,Div II 的宽度为 75%。当我使用响应式设计达到 320 像素(iphone 纵向)时,Div II 低于 Div I,我认为这是正常过程。

我想做的是使用 float 将 Div II 置于 Div I 之上,这如何通过 css 实现?

最佳答案

Working Fiddle

.div1 {
width: 25%;
float:left;
background:orange;
}

.div2 {
width:75%;
float: right;
background:red;
}

@media screen and (max-width: 320px) {
.div1, .div2 {
width: 100%;
display: block;
float: none;
clear: both;
}
.div1{
position:relative;
top:100px;
}
.div2{
position:absolute;
top:0;
height:100px;
}
}

关于css - 响应式网页设计 float 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22220451/

相关文章:

html - Bootstrap glyphicon-cog 实际上显示了 glyphicon-envelope?

html - 邻居之间的垂直边距不一致

html - CSS -align 3 responsive Divs- left right with position fixed and center normal CSS -align 3 responsive Divs- left right 位置固定,居中正常

html - Bootstrap 表响应无法正常工作-宽度问题

html - 如何在不影响HTML和CSS背景图片的情况下调整图片

html - CSS float right 无法正常工作

responsive-design - Dotnetnuke 7 .less 集成

css - 响应式背景图片 : How to handle height?

html - CSS - 填充不起作用

html - 网站未调整为移动设备