如果您全屏查看演示,我会尝试对齐每个 div 的所有内部内容 - 例如您会注意到中间的青色 div 的内容与第一个和第三个青色 div 的内容对齐不均。
很难解释,但是看看中间青色div中图标的位置与其他图标相比。如果每个 div 中的文本数量不同,我怎样才能使内部内容与其他青色 div 垂直对齐?
.sections {
background: #f2f2f2;
width: 100%;
height: auto;
text-align: center;
padding: 100px 10%;
box-sizing: border-box;
}
#foster-cta-wrap {
background: yellow;
display: flex;
justify-content: space-evenly;
flex-direction: row;
align-items: center;
flex-flow: row wrap;
}
.foster-cta {
box-sizing: border-box;
width: 250px;min-width: 250px;
height: 200px;
background: cyan;
border: 1px solid grey;
margin-top: 30px;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
display: inline-flex;
}
.foster-top {
display: block;
font-size: 30px;
}
.foster-middle {
display: block;
text-transform: uppercase;
font-size: 22px;
font-weight: 400;
}
.foster-bottom {
display: block;
font-weight: 300;
font-size: 16px;
}
.foster-cta:hover {
background: lightgreen;
cursor: pointer;
}
.foster-top a:link, .foster-top a:visited, .foster-middle a:link, .foster-middle a:visited, .foster-bottom a:link, .foster-bottom a:visited {
text-decoration: none;
color: #333;
}
<section class="sections">
<article id="foster-cta-wrap">
<nav class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">search engine optimisation</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav><!--
--><nav class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">SEO</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav><!--
--><nav onclick="location.href='#';" class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">search engine optimisation</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav>
</article>
</section>
最佳答案
.sections {
background: #f2f2f2;
width: 100%;
height: auto;
text-align: center;
padding: 100px 10%;
box-sizing: border-box;
}
#foster-cta-wrap {
background: yellow;
display: flex;
justify-content: space-evenly;
flex-direction: row;
align-items: center;
flex-flow: row wrap;
}
.foster-cta {
box-sizing: border-box;
width: 250px;min-width: 250px;
height: 200px;
background: cyan;
border: 1px solid grey;
margin-top: 30px;
text-align: center;
}
.foster-top {
display: block;
font-size: 30px;
padding: .5em;
}
.foster-middle {
display: block;
text-transform: uppercase;
font-size: 22px;
font-weight: 400;
}
.foster-bottom {
display: block;
font-weight: 300;
font-size: 16px;
}
.foster-cta:hover {
background: lightgreen;
cursor: pointer;
}
.foster-top a:link, .foster-top a:visited, .foster-middle a:link, .foster-middle a:visited, .foster-bottom a:link, .foster-bottom a:visited {
text-decoration: none;
color: #333;
}
<section class="sections">
<article id="foster-cta-wrap">
<nav class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">search engine optimisation</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav>
<nav class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">SEO</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav>
<nav onclick="location.href='#';" class="foster-cta">
<span class="foster-top">icon</span>
<span class="foster-middle"><a href="#">search engine optimisation</a></span>
<span class="foster-bottom">increase the rankings in search results.</span>
</nav>
</article>
</section>
这就是我要做的:我删除了 .foster-cta
上的所有 flex 格式,并将其替换为 text-align: center;
。然后,我向 .foster-top
添加了 padding 以使其看起来更好并且不与其他文本联系。标题现在被推到主标题上,但这可以通过为它们中的任何一个设置 padding
/margin
值来解决。
关于html - 将内部内容与附近 div 的内容对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062002/