柔性箱内的div收缩包装(Making divs inside flex boxes shrink

编程入门 行业动态 更新时间:2024-10-27 20:24:59
柔性箱内的div收缩包装(Making divs inside flex boxes shrink-wrap)

如何才能让这些div flex盒子缩水呢?

IE浏览器。 使这些:

进入这些:

http://jsfiddle.net/frank_o/35hk7L84/1/

就好像一个人要设置flex-direction: row; 除了我不能让他们在同一行上。

.main {
    display: flex;
    flex-direction: column;
    /* flex-direction: row; */
}
.other {
    color: white;
    background: blue;
    margin: 10px;
} 
  
<div class="main">
    <div class="other">
        <p>Hello world</p>
    </div>
    <div class="other">
        <p>Hello other world</p>
    </div>
</div> 
  
 

How would one go about making these div flex boxes shrink-wrap?

Ie. making these:

Into these:

http://jsfiddle.net/frank_o/35hk7L84/1/

As if one were to set flex-direction: row; except I can't have them on the same line.

.main {
    display: flex;
    flex-direction: column;
    /* flex-direction: row; */
}
.other {
    color: white;
    background: blue;
    margin: 10px;
} 
  
<div class="main">
    <div class="other">
        <p>Hello world</p>
    </div>
    <div class="other">
        <p>Hello other world</p>
    </div>
</div> 
  
 

最满意答案

以下是您正在查找的内容(更改各个元素的display ):

.main {
  display: inline-flex;
  flex-direction:column;
}

.other {
    color: white;
    background: blue;
    margin: 10px;   
    display:table;
} 
  
<div class="main">
    <div class="other">
        <p>Hello world</p>
    </div>
    <div class="other">
        <p>Hello other world</p>
    </div>
</div> 
  
 

有用的资源: https : //developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes

其他: http : //css-tricks.com/snippets/css/a-guide-to-flexbox/

Here is what you are looking for (change the display of the individual elements):

.main {
  display: inline-flex;
  flex-direction:column;
}

.other {
    color: white;
    background: blue;
    margin: 10px;   
    display:table;
} 
  
<div class="main">
    <div class="other">
        <p>Hello world</p>
    </div>
    <div class="other">
        <p>Hello other world</p>
    </div>
</div> 
  
 

Useful resources: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes

Other: http://css-tricks.com/snippets/css/a-guide-to-flexbox/

更多推荐

本文发布于:2023-08-06 04:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1443991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:柔性   箱内   div   Making   shrink

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!