Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使flexbox统一?_Html_Css_Flexbox - Fatal编程技术网

Html 如何使flexbox统一?

Html 如何使flexbox统一?,html,css,flexbox,Html,Css,Flexbox,我的CSS是这样的。最后一行出现了一个不必要的空格。如何使flex box统一。products1是最外层的div,catlist1是中间的div,d1是最内层的div:- .products1{ position:absolute; top:800px; padding:50px; background: #f2f2f2; display:flex; margin-left: 15px;

我的CSS是这样的。最后一行出现了一个不必要的空格。如何使flex box统一。products1是最外层的div,catlist1是中间的div,d1是最内层的div:-

 .products1{
        position:absolute;
        top:800px;
        padding:50px;
        background: #f2f2f2;
        display:flex;
        margin-left: 15px;
        width: 90%;
    }

    .catlist1{
        flex-wrap: wrap;
        width: 100%;    
        padding:0px;
        display:flex;
    }

    .d1{
        display: block;
        background:white;
        margin-left: auto;
        margin-right: auto;
        background-size: cover; 
        margin: 10px auto;
        width:100px;
        height:25px;
        border:0 solid #dee0e2;
        display: inline;
        padding:50px;
        text-align: center;
        box-shadow: 1px 5px 5px 0 rgba(0,0,0,.3);
    }
我得到的输出如下:- [![This][1]][1]

HTml:-

<div class="products1">
   <div class="catlist1">
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
     <div class="d1"></div>
   </div>
</div>

超出自动模式的距离
余量:10px自动
页边距:3px 3px

但如果您想要更精确,请使用
@媒体屏幕和

你会有
原因是
d1
margin
语句中的
auto
。它使应用到的图元居中,从而使最后一行中的图元均匀隔开


如果您想保持
自动
,并将最后一行显示为其他行,那么如果没有JavaScript或切换到
display:grid
以及针对不同宽度的媒体查询,我认为这是不可能的。如果您只想填充最后一行,并为边距找到不同的解决方案,则在catlist的末尾添加另一个带有CSS规则的
div
,即
flex grow:1
,更改d1类的边距属性,如下所示:

.d1 {
        display: block;
        background:white;
        margin-left: auto;
        margin-right: auto;
        background-size: cover; 
        **margin: 10px;**
        width:100px;
        height:25px;
        border:0 solid #dee0e2;
        display: inline;
        padding:50px;
        text-align: center;
        box-shadow: 1px 5px 5px 0 rgba(0,0,0,.3);
}

作为
页边距:10px自动
将每个
flex项目的左右边距
设置为auto,从而导致最后一行项目数量较少时左右边距分布不均匀。

您是否也可以发布HTML代码?添加了示例HTML@UmboOk谢谢。我不知道你是否需要一个每行4个元素的网格,或者元素是否应该根据可用空间进行包装。另外,
.d1
项目的数量是固定的还是可变的?我想要的是内部div的宽度应该是1.fixed,是的,每行4个元素。d1项目是可变的。提供的HTML只是为了给@Umbo一个粗略的概念