作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的网络元素中使用 Flexbox。我之前已经能够成功地使用它,但在这种情况下,我显然有某种样式或结构妨碍了 Flexbox 的工作。
似乎 justify-content
、align-items
和 align-content
属性都没有做任何事情。但是 flex-direction
和 flex-wrap
确实有效。
相关的 HTML:
<div class="category-container">
<!-- Repeat this section for all the blocks -->
<div class="flexy">
<a href="#">
<div class="categories">
<h2>Title</h2>
<img src="insertimghere.jpg" />
<p>
This is an example description. Look at all
this information. Wow, such info, very description.
</p>
</div>
</a>
</div>
<!-- Repeat this section for all of the blocks -->
</div>
相关 CSS:
/* Parent Div - Flexbox */
.category-container {
padding:0 2% 0 2%;
display:flex;
flex-direction:row;
flex-wrap:wrap;
/* Next three lines have no effect when changed */
justify-content:flex-start;
align-items:flex-start;
align-content:flex-start;
}
/* Child Div - Flexbox */
.flexy {
margin:auto;
padding-bottom:30px;
}
/* Div inside Flexy */
.categories {
width:350px;
height:420px;
margin:auto;
background-color:#fff;
padding:30px 15px 10px 15px;
box-shadow:0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
最佳答案
此 CSS 的失败是 margin:auto;
在 .flexy
上。删除它并用 margin:5px 10px;
代替。
试试下面的例子(https://jsfiddle.net/sebastianbrosch/63fe9t5n/3/):
/* Parent Div - Flexbox */
.category-container {
padding:0 2% 0 2%;
display:flex;
flex-direction:row;
flex-wrap:wrap;
/* Next three lines have no effect when changed */
justify-content:flex-start;
align-items:flex-start;
align-content:flex-start;
}
/* Child Div - Flexbox */
.flexy {
margin:5px 10px;
padding-bottom:30px;
}
/* Div inside Flexy */
.categories {
width:350px;
height:420px;
margin:auto;
background-color:#fff;
padding:30px 15px 10px 15px;
box-shadow:0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
<div class="category-container">
<!-- Repeat this section for all the blocks -->
<div class="flexy">
<a href="#">
<div class="categories">
<h2>Title</h2>
<img src="insertimghere.jpg" />
<p>
This is an example description. Look at all
this information. Wow, such info, very description.
</p>
</div>
</a>
</div>
<div class="flexy">
<a href="#">
<div class="categories">
<h2>Title</h2>
<img src="insertimghere.jpg" />
<p>
This is an example description. Look at all
this information. Wow, such info, very description.
</p>
</div>
</a>
</div>
<div class="flexy">
<a href="#">
<div class="categories">
<h2>Title</h2>
<img src="insertimghere.jpg" />
<p>
This is an example description. Look at all
this information. Wow, such info, very description.
</p>
</div>
</a>
</div>
<div class="flexy">
<a href="#">
<div class="categories">
<h2>Title</h2>
<img src="insertimghere.jpg" />
<p>
This is an example description. Look at all
this information. Wow, such info, very description.
</p>
</div>
</a>
</div>
<!-- Repeat this section for all of the blocks -->
</div>
关于html - Flexbox 父属性不起作用(对齐内容、对齐内容、对齐元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34318853/
我是一名优秀的程序员,十分优秀!