css - Flexbox css3 使响应居中的行?

标签 css twitter-bootstrap-3 flexbox responsiveness

I have a 3 box example here all horizontally centered and trying to make them responsive, so if the resolution drops they will stack. I've tried doing this with flex box because it allows any box to grow and still lines up. Originally I put the boxes in bootstrap 3 row with the cols-lg (md etc) set but it would never unstack them! The outer wrapper (.wpr) will on implementation be a banner which is why I would like the positional boxes horizontally aligned where possible.

注意:答案不一定要用flexbox!

Full width

Reduced Screen

Here is the fiddle

HTML

<div class="wpr">
    <div class="box" style="background-color: red;">A B C</div> 
    <div class="box" style="background-color: blue;">2</div>   
    <div class="box" style="background-color: pink;">3</div>   
</div>

CSS

.wpr
{
    width: 100%;    
    background: grey;
    padding: 10px 30px;    
    display: flex;
    justify-content: center; /* align horizontal */
    align-items: top; /* align vertical */    
}

div.box 
{
    width: 200px;    
    min-width: 200px;    
    float: left;
    margin: 0 5px;
    padding: 30px;
    text-align: center;
    color: white;
    font-size: 72px;    
    min-height: 100px;
}

最佳答案

您可以将 flex-wrap: wrap; 添加到 .wpr,如我的 demo 所示.

关于css - Flexbox css3 使响应居中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42556243/

相关文章:

javascript - 关闭警报时引导内容平滑滑动

html - td 中的 css 3 图像

jquery - CSS/JS/Jquery 中的空格是否占用空间?

javascript - 在其他 div 下隐藏固定定位的 div(视差)

css - 如何更改 Bootstrap 3 选中的选项背景颜色

html - Bootstrap : How to "stick" a button over an image when re-sizing

html - 在列之间添加空格而不丢失网格系统布局

html - Flex Box 顶部对齐和居中对齐

html - Flexbox 表格标题左对齐与滚动条断开

html - IE8继承父元素的宽度