这是我尝试创建图像网格的HTML代码:
来源:https://www.w3schools.com/howto/howto_css_image_grid_responsive.asp
我想设置屏幕的图像显示中心,但是对齐项目或对齐 - 自我不要同时:
<div style="align-items: center;align-content: center;align-self: center;">
<%foreach $datalist as $row%>
<div class="row">
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
</div>
<%/foreach%>
</div>
结果:
为什么对齐项目中心不起作用?
如何显示屏幕中心?
答案 0 :(得分:1)
content
div
经线div
而不是经线.row{
display: flex;
justify-content: center;
align-items: center;
}
align-items
或设置width
答案 1 :(得分:1)
这将有效:
<div>
<%foreach $datalist as $row%>
<div class="row" style="style="display: flex; justify-content: center; align-items: center;">
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
<div class="column">
<img src="shared/img/<%$row.image_name%>">
<p><%$row.title%></p>
</div>
</div>
<%/foreach%>
</div>
答案 2 :(得分:0)