然而,我想要发生的事情应该是这样的:
以下是我粗略的一些代码
.Container {
text-align: center;
margin-left: 10px;
margin-right: 10px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
align-content: center;
}
.Items {
margin-bottom: 7px;
width: 80px;
height: 80px;
text-align: center;
font-size: 12px;
line-height: 10px;
border: 0px;
padding-bottom: 7px;
align-self: center;
}
<div class="Container">
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
</div>
更新 谢谢那些回复的人。但是,我忘了添加这些东西。
justify-content: space-around
align-items: center; align-content: center;
问题在于:是否可以同时使用两者?
答案 0 :(得分:1)
而不是justify-content: space-around
使用justify-content: flex-start
。
演示:http://jsfiddle.net/rsvmsku6/
更新(根据评论):
有关创建水平居中网格的指导,但子元素左对齐,请参阅以下帖子:
答案 1 :(得分:0)
从Container中删除以下css:
justify-content: space-around;
答案 2 :(得分:0)
justify-content: space-around;
这是你的问题。如果删除该行,则项目也会按您的要求显示
space-around
:
项目均匀分布在线条周围,空间相等
flex-start
(默认)
项目在起始行打包
答案 3 :(得分:0)
您不需要某些元素。
align-items
align-content
您还需要将justify-content
设置为flex-start
,并始终将其设置为左侧。
.Container {
text-align: center;
margin-left: 10px;
margin-right: 10px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
width: 320px;
}
.Items {
margin-bottom: 7px;
width: 80px;
height: 80px;
text-align: center;
font-size: 12px;
line-height: 10px;
border: 0px;
padding-bottom: 7px;
align-self: center;
}
&#13;
<div class="Container">
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
<div class="Items">
<img height="40px" width="40px" src="http://img10.deviantart.net/af75/i/2014/242/1/9/kawaii_potato_by_hashtagpony-d7xbs1t.png" />
<br/>
<span>Icon 1</span>
</div>
</div>
&#13;