如何在元素之间添加空间,以便它们填充容器div? [英] How to add space between elements so they fill their container div?

查看:55
本文介绍了如何在元素之间添加空间,以便它们填充容器div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 spans 之间添加空格,以使最左边和最右边的spans靠近 inner div 的边缘.我尝试添加以下规则,但没有效果.

I want to add space between spans so that the leftmost and rightmost spans will be close to the edges of the inner div. I've tried to add the following rule, but it had no effect.

span.icon-square {
    margin: 0 auto;
}

span.icon-square:first-child {
    margin-left: 0;
}

span.icon-square:last-child {
    margin-right: 0;
}

下面给出了我要实现的目标的说明:

The illustration of what I'm trying to achieve is given below:

那么,我想念什么?

推荐答案

您可以使用Flexboxjustify-content: space-between来做到这一点.

You can do this with Flexbox and justify-content: space-between.

.content {
  display: flex;
  justify-content: space-between;
  max-width: 400px;
  margin: 0 auto;
  background: #A0C5E8;
  padding: 10px 0;
}

span {
  width: 50px;
  height: 50px;
  background: black;
}

<div class="content">
  <span></span>
  <span></span>
  <span></span>
  <span></span>
</div>

这篇关于如何在元素之间添加空间,以便它们填充容器div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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