gpt4 book ai didi

html - CSS 对齐彼此相邻的元素居中

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

我有以下内容:

enter image description here

html

<div class="img-container">
<div class="google">
<a href="path to app on play store"><img class="google-img"
src="images/google-play-badge.png"></a>
</div>

<div class="apple">
<a href="path to app on apple store"><img class="apple-img"
src="images/Download_on_the_App_Store_Badge_US-UK_135x40.svg"></a>
</div>

<div class="web">
<a href="www/index.html"><img class="web-img"
src="images/view-on-web.svg"></a>
</div>
</div>

CSS

.img-container {
text-align: center;
}

.img-container .apple, .img-container .google, .img-container .web {
float: left;
padding: 10px;
padding-left: 20px;
}

.img-container .google {
padding-top: 4px;
padding-left: 0px;
padding-right: 0px;
}

如您所见,我做了一个 float: left; 以便 3 个元素彼此相邻排成一行。我还尝试了 text-align: center;,尝试将元素居中,但没有效果。

问题

如何让这 3 个元素并排排列并在页面中居中?

谢谢

最佳答案

使用 display:inline-block; 而不是 float 就可以了

.img-container {
text-align: center;
}

.img-container .apple,
.img-container .google,
.img-container .web {
display:inline-block;
padding: 10px;
padding-left: 20px;
}

.img-container .google {
padding-top: 4px;
padding-left: 0px;
padding-right: 0px;
}
<div class="img-container">
<div class="google">
<a href="path to app on play store"><img class="google-img" src="images/google-play-badge.png"></a>
</div>

<div class="apple">
<a href="path to app on apple store"><img class="apple-img" src="images/Download_on_the_App_Store_Badge_US-UK_135x40.svg"></a>
</div>

<div class="web">
<a href="www/index.html"><img class="web-img" src="images/view-on-web.svg"></a>
</div>
</div>

关于html - CSS 对齐彼此相邻的元素居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44309587/

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