gpt4 book ai didi

html - 在 flexbox 列中水平居中文本

转载 作者:太空狗 更新时间:2023-10-29 16:39:35 25 4
gpt4 key购买 nike

我正在尝试使用 flexbox 创建一个简单的页脚。但我想将 flexbox 列中的文本 block 居中,而不是 text-align: center,但实际上将文本 block 居中列中。

这是一个 jsfiddle: https://jsfiddle.net/f2yb72c9/

HTML

<div class="row-flex--footer">
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Company</h4>
<ul>
<li> <a class="footer__link">About us</a></li>
<li><a class="footer__link">Careers</a></li>
<li> <a class="footer__link">News</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Surgeons</h4>
<ul>
<li> <a class="footer__link">3D Business Manager</a></li>
<li><a class="footer__link">Plans &amp; Pricing</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Patients </h4>
<ul>
<li> <a class="footer__link">Find a Crisalix surgeon</a></li>
<li><a class="footer__link">Community</a></li>
</ul>
</nav>
</div>
</div>
</footer>

CSS

ul{
list-style:none;
padding:0;
}
.row-flex--footer {
align-content: center;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}

footer .column {
flex: 1 1 auto;
}
@media (min-width: 868px) {
footer .column {
flex: 1 1 33.333%;
}
}

最佳答案

请查看下面的 JSFiddle。我建议您不要在样式表中使用 %,而是使用“cols”。您正在寻找的是:

display: flex;
align-items: center;
justify-content: center;

它用于在不使用文本对齐的情况下将内容集中在 flexbox 列中。

    ul{
list-style:none;
padding:0;
}
.row-flex--footer {
align-content: center;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}

footer .column {
flex: 1 1 auto;
background: coral;
margin: 5px;
display: flex;
align-items: center;
justify-content: center;
}
@media (min-width: 868px) {
footer .column {
flex: 1 1 33.333%;
}
}
    <footer>

<div class="row-flex--footer">
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Company</h4>
<ul>
<li> <a class="footer__link">About us</a></li>
<li><a class="footer__link">Careers</a></li>
<li> <a class="footer__link">News</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Surgeons</h4>
<ul>
<li> <a class="footer__link">3D Business Manager</a></li>
<li><a class="footer__link">Plans &amp; Pricing</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Patients </h4>
<ul>
<li> <a class="footer__link">Find a Crisalix surgeon</a></li>
<li><a class="footer__link">Community</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Support </h4>
<ul>
<li> <a class="footer__link">Surgeon Help Center</a></li>
<li><a class="footer__link">Patient Help Center</a></li>
<li><a class="footer__link">Surgeon Help Center</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Legal</h4>
<ul>
<li> <a class="footer__link">Universal terms</a></li>
<li><a class="footer__link">Privacy policy</a></li>
<li><a class="footer__link">Security statements</a></li>
</ul>
</nav>
</div>
<div class="column">
<nav>
<h4 class="hl--list footer__hl">Social</h4>
<ul>
<li> <a class="footer__link">Facebook</a></li>
<li><a class="footer__link">Twitter</a></li>
<li><a class="footer__link">Youtube</a></li>
</ul>
</nav>
</div>
</div>
</footer>

关于html - 在 flexbox 列中水平居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36624751/

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