【发布时间】:2023-04-06 04:29:01
【问题描述】:
<div style="width:100%;text-align: center;">
<div style="float:left; width:150px;max-width:150px;margin:5px">
<div style="display:block;margin: 0 auto;"> <img style="height:auto;width:auto;max-width: 150px;max-height: 150px;" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN_preview.jpg"> </div>
</div>
<div style="float:left; width:150px;max-width:150px;margin:5px">
<div style="display:block;margin: 0 auto;"> <img style="height:auto;width:auto;max-width: 150px;max-height: 150px;" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN_preview.jpg"> </div>
</div>
<div style="float:left; width:150px;max-width:150px;margin:5px">
<div style="display:block;margin: 0 auto;"> <img style="height:auto;width:auto;max-width: 150px;max-height: 150px;" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN_preview.jpg"> </div>
</div>
<div style="float:left; width:150px;max-width:150px;margin:5px">
<div style="display:block;margin: 0 auto;"> <img style="height:auto;width:auto;max-width: 150px;max-height: 150px;" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN_preview.jpg"> </div>
</div>
<div style="float:left; width:150px;max-width:150px;margin:5px">
<div style="display:block;margin: 0 auto;"> <img style="height:auto;width:auto;max-width: 150px;max-height: 150px;" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN_preview.jpg"> </div>
</div>
我想在水平中心进行图像预览。如何水平居中对齐这个 div?我知道是因为从左侧开始浮动左行,但我希望该行从中心对齐开始。
【问题讨论】:
-
不要使用绝对定位
-
那如何水平居中对齐?
-
从图像中删除绝对位置。将 div 上的 Float:left 替换为:“display:block;margin:auto;”。
-
最简单的方法(但老式方法)是将图像标签放在
标签之间。