【问题标题】:Why is the flex-wrap:wrap property causing my divs to get uneven sizes? [duplicate]为什么 flex-wrap:wrap 属性会导致我的 div 大小不均? [复制]
【发布时间】:2018-10-31 17:05:12
【问题描述】:

我的容器和 flex-wrap:wrap 使用了 flex box,但是我的子 div 变得不均匀。如何修复它?

.container{

    margin: 0 auto;
    flex-wrap: wrap;
    width: 100%;    
    padding:10px;
    display:flex;
}

.child{
    flex:1;  
    margin: 10px;
    vertical-align: center;
    width:100px;
    length:100px;
    border:2px solid gray;
    display: inline;
    float:left;
    padding:65px;
    background-image:;  
    text-align: center;
}

假设有 11 个子 div,它显示在三行中。现在最后一行仅显示 11 个 div 中剩余的 3 个 div,因此它水平拉伸了这些 div。

因此,我试图保持所有 div 大小相同,并使最后一行 div 对齐中心和相同大小。怎么办?

【问题讨论】:

  • 添加相关的HTML或制作sn-p。

标签: html css flexbox


【解决方案1】:

移除 flex:1 并且不需要在 flex 框中浮动:left

【讨论】:

  • 同样采用.container 样式justify-content: space between;align-items: center; 而不是.child 中的垂直对齐方式
  • ok 现在所有尺寸都一样了,但是如何将它对齐到容器的中心以及容器的最后一行 divs 中心?
  • 仍然左对齐
  • justify-content: center; 加上.child 的边距以实现均匀间距
猜你喜欢
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 1970-01-01
  • 2011-06-29
  • 2017-08-11
  • 2014-10-08
  • 1970-01-01
  • 2021-09-14
相关资源
最近更新 更多