【发布时间】:2018-02-14 21:16:10
【问题描述】:
我正在构建如下图所示的布局...目标是图像位于左侧,宽度固定。图片右侧的文字会相应对齐并占用可用宽度。
最后,目标是这些项目堆叠成一个网格。
我在让项目正确对齐时遇到问题,这就是我所拥有的:
.feature-items {
background: #CCC;
box-sizing: border-box;
width: 100%;
padding: 0px;
}
.feature-item--wrapper {
background: #efefef;
display: inline-block;
flex-direction: row;
box-sizing: border-box;
width: 336px;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.img-wrapper {
box-sizing: border-box;
width: 88px;
padding-right: 24px;
}
.img-wrapper,
img {
width: 64px;
height: 64px;
}
.text {
box-sizing: border-box;
padding-top: 24px;
padding-bottom: 24px;
flex: 1 1 auto;
}
<div class="feature-items">
<div class="feature-item--wrapper">
<div class="img-wrapper">
<img src="http://clipground.com/images/minecraft-server-clipart-64x64-9.png" width="64">
</div>
<div class="text">
<strong class="feature-title">Title</strong>
<p class="feature-description">This is a sentence description, hello world.</p
</div>
</div>
<div class="feature-item--wrapper">
<div class="img-wrapper">
<img src="http://clipground.com/images/minecraft-server-clipart-64x64-9.png" width="64">
</div>
<div class="text">
<strong class="feature-title">Title</strong>
<p class="feature-description">This is a sentence description, hello world.</p
</div>
</div>
<div class="feature-item--wrapper">
<div class="img-wrapper">
<img src="http://clipground.com/images/minecraft-server-clipart-64x64-9.png" width="64">
</div>
<div class="text">
<strong class="feature-title">Title</strong>
<p class="feature-description">This is a sentence description, hello world.</p
</div>
</div>
<div class="feature-item--wrapper">
<div class="img-wrapper">
<img src="http://clipground.com/images/minecraft-server-clipart-64x64-9.png" width="64">
</div>
<div class="text">
<strong class="feature-title">Title</strong>
<p class="feature-description">This is a sentence description, hello world.</p
</div>
</div>
</div>
如果我做错了什么,任何帮助将不胜感激?谢谢
【问题讨论】:
-
您是否有特殊原因正在使用或想要使用 flexbox 而不是 CSS 网格布局来将项目对齐到网格中?