gpt4 book ai didi

html - Flexbox 父属性不起作用(对齐内​​容、对齐内容、对齐元素)

转载 作者:行者123 更新时间:2023-11-28 16:37:16 26 4
gpt4 key购买 nike

我在我的网络元素中使用 Flexbox。我之前已经能够成功地使用它,但在这种情况下,我显然有某种样式或结构妨碍了 Flexbox 的工作。

似乎 justify-contentalign-itemsalign-content 属性都没有做任何事情。但是 flex-directionflex-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);
}

我有什么: What I Have

我想要的: What I Want

最佳答案

此 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com