【问题标题】:Responsive Layout : How to switch positions in smartphone layout响应式布局:如何在智能手机布局中切换位置
【发布时间】:2016-04-07 16:31:19
【问题描述】:

我该如何解决这个响应式布局案例: 我有三个盒子。 在宽屏幕上,我希望其中两个在左侧,宽度固定,另一个在右侧。 在小屏幕上,我希望所有框都变成 100%,而正确的框位于其他两个之间。

我做了一个几乎可以工作的小提琴,但我需要在宽模式下消除这个差距。

https://jsfiddle.net/ypmgo7no/3/

.leftfixed {
  float:left;
  width:200px;
  background:purple;
  height:50px;
}

.right {
  margin-left:220px;
  background:yellow;
  height:100px;
}

@media (max-width:500px) {
  .leftfixed {
    float:none;
      width:100%;
      background:blue;
   }

   .right {
     margin-left:0;
     }
}

看到问题:(不好意思,刚刚发现图片中的“Wide mode”和“Small mode”互换了) Image

【问题讨论】:

  • 媒体查询不是问题。请阅读问题。谢谢
  • 我看不出那些小提琴之间的差距?
  • @SatejS:对不起,我更新了小提琴,盒子需要有高度:jsfiddle.net/ypmgo7no/3
  • 如果你说的是两个紫色 div 之间的间隙,那是因为右边黄色 div 的高度..

标签: html css responsive-design


【解决方案1】:

你想要这样吗?

.leftfixed {
  float:none;
  width:200px;
  background:purple;
  height:100px;
}

.right {
    left: 220px;
    background: yellow;
    height: 200px;
    position: absolute;
    width: 100%;
    top: 7px;
  }

@media (max-width:500px) {
  .leftfixed {
    float:none;
      width:100%;
      background:blue;
   }
   
   .right {
     margin-left:0;
     position:inherit;
     
     }
}
<div class="leftfixed">
box left fixed width 1
</div>

<div class="right">
box right
</div>

<div class="leftfixed">
box left fixed width 2
</div>

【讨论】:

  • 好的,但我认为可能有一个没有位置的解决方案:绝对:-/
  • 好的。没问题。我会尝试而不尝试位置:绝对。等一下。
  • 你不想在任何地方使用位置属性??
  • 最好不要 :) 但我不知道这可能
  • 因为必须使用位置属性。我做了更新仍然有使用位置属性
【解决方案2】:

这是我在最后一个 div 中添加类 bottom 并在原始代码中添加 position:relativebottom:100px 的另一种方法。

.leftfixed {
  float:left;
  width:200px;
  background:purple;
  height:100px;
}

.right {
    margin-left: 220px;
    background: yellow;
    height: 200px;
    /*position: absolute;*/
    width: 100%;
    top: 7px;
  }
  .bottom{
  	    position: relative;
    	bottom: 100px;
  }

@media (max-width:500px) {
  .leftfixed {
    float:none;
      width:100%;
      background:blue;
   }
   
   .right {
     margin-left:0;
   
     
     }
}
<div class="leftfixed">
box left fixed width 1
</div>

<div class="right">
box right
</div>

<div class="leftfixed bottom">
box left fixed width 2
</div>

【讨论】:

  • 你应该更新你的最后一个答案,而不是发布两个答案,或者在最后一个答案中添加这个..
  • 是的。实际上我单独添加了第二个答案,因为@flasher 会理解。
  • 请告诉我。我的回答正确与否?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-30
相关资源
最近更新 更多