gpt4 book ai didi

javascript - 如何居中对齐图标和文本?

转载 作者:行者123 更新时间:2023-12-01 23:18:17 30 4
gpt4 key购买 nike

如何垂直堆叠和对齐图标及其各自的文本,并水平居中对齐?并使其完全响应移动设备?

enter image description here

我的尝试

li {
margin: 0 90px;
display: inline;
}

.num {
margin: 0 150px;
display: inline;
}

ul {
list-style: none outside none;
margin: 0;
padding: 50;
text-align: center;
}

ul li i {
text-align: center;
}
<!-- script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<ul>
<li><i class="fas fa-phone">
</i>
</li>
<li><i class="fas fa-map">
</i>
</li>
<li><i class="fas fa-paper-plane">
</i>
</li>
</ul>
<ul class="num">
<li><a href="tel:5551234567">Call (555)123-4567</a></li>
<li>Box 564, Disneyland</li>
<li><a href="mailto:EmailAddress@. XYZ.com"> Email.com </a></li>
</ul>

最佳答案

我希望这就是你要找的。

ul {
display:flex;
}

ul li i{
padding:10px;
}
ul li {
display:flex;
flex:1;
padding:20px;
flex-direction:column;
text-align:center;
}

@media only screen and (max-width: 600px){
ul {
flex-direction:column;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<ul>
<li>
<i class="fas fa-phone"></i>
<a href="tel:5551234567">Call (555)123-4567</a>
</li>
<li>
<i class="fas fa-map"> </i>
<span>Box 564, Disneyland<span>
</li>
<li>
<i class="fas fa-paper-plane"></i>
<a href="mailto:EmailAddress@. XYZ.com"> Email.com </a>
</li>
</ul>
</body>
</html>

关于javascript - 如何居中对齐图标和文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68532140/

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