gpt4 book ai didi

html - 在图像和中心周围添加 div 容器

转载 作者:太空宇宙 更新时间:2023-11-04 07:01:46 25 4
gpt4 key购买 nike

我正在做一个网站,我想在内容区域的中心对齐 4 个圆圈。该示例可在 invisionbilling.com/stackoverflow 找到。我现在有一些东西可以完成这项工作,但我知道不同的窗口大小、不同的图片大小等会出现问题。如何设置 div 容器的高度以自动环绕 4 个圆圈/图像?有没有办法使用 margin-left 和 margin-right 自动居中?我为所有这些尝试了“自动”,但它没有完成这项工作。谢谢!

HTML

<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>

CSS

.circles {
display: block !important;
float: left !important;
margin: 10px !important;
}

.wrapper {
height: 175px;
width: 100%;
margin-left: 225px;
}

最佳答案

尝试使用 flexbox 而不是 float ,并且永远不要使用 !important:

<!DOCTYPE html>
<html>
<head>
<style>
.circles {
margin: 10px;
}

.wrapper {
height: 175px;
width: 100%;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>

<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>
</body>
</html>

关于html - 在图像和中心周围添加 div 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51973743/

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