包装时如何更改弹性顺序 [英] How to change the flex order when wrapping

查看:64
本文介绍了包装时如何更改弹性顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实现一些可以根据屏幕尺寸进行渲染的东西:

I would like to achieve something that renders like this depending on the screen size:

+---------------------------+
|  A  |       B       |  C  |
+---------------------------+

+---------------+
|   A   |   C   |
|       B       |
+---------------+

如果所有大小都固定,我可以使用flex order属性进行管理 但是我的C容器的大小不是固定的,因此不能使用静态媒体查询.

if all size are fixed, i can manage using the flex order property but the size of my C container is not fixed and so I can't use a static media query.

有没有办法做到这一点?

Is there a way to achieve this?

我做了一个足够好的近似:在一个媒体查询中,选择可能需要包装的所有屏幕,将B容器的order更改为大尺寸,同时,将其设置为min-width到100%会强制换行.

I managed a good enough approximation: In a media query selecting all screens that might need wrapping, I change the order of the B container to something big, and at the same time, I set its min-width to 100% which forces the wrap.

推荐答案

您可以使用flex: 0 0 100%使b元素变为全角,并使用媒体查询

You can make b element full width with flex: 0 0 100% and change order to order: 2 with media queries DEMO

* {
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
}
.content {
  display: flex;
  flex-wrap: wrap;
}
.b {
  background: lightblue;
}
.a, .b, .c {
  border: 1px solid black;
  flex: 1;
  padding: 10px;
}
@media(max-width: 768px) {
  .b {
    flex: 0 0 100%;
    order: 2;
  }
}

<div class="content">
  <div class="a">A</div>
  <div class="b">B</div>
  <div class="c">C</div>
</div>

这篇关于包装时如何更改弹性顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆