html - Four pictures sharing a corner : alternative HTML+CSS layout?
问题描述
I am trying to setup four image panels with a common corner. Images are randomly picked and often have different dimensions.
I managed to get a correct layout using absolute positioning of pictures inside relative cells of a table :
table {
width: 100%;
}
td {
position: relative;
}
img {
position: absolute;
}
.top img {
bottom: 0;
}
.bottom img {
top: 0;
}
.left img {
right: 0;
}
.right img {
left: 0;
}
<table>
<tr>
<td class="top left">
<img src="http://placekitten.com/200/300"/>
</td>
<td class="top right">
<img src="http://placekitten.com/300/300"/>
</td>
</tr>
<tr>
<td class="bottom left">
<img src="http://placekitten.com/300/100"/>
</td>
<td class="bottom right">
<img src="http://placekitten.com/200/200"/>
</td>
</tr>
</table>
However td
s have a zero height because of the absolute positioning. As a consequence, I struggle to place the whole table at the correct position inside the whole page.
I am wondering if there is another way to achieve this layout ?
解决方案
试试弹性盒子。https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/
.Aligner {
display: flex;
align-items: center;
justify-content: center;
}
.Aligner-item {
max-width: 50%;
}
.flex-item img{
vertical-align:top;
}
<div class="Aligner">
<div class="Aligner-item">
<div class="flex-item">
<img src="http://placekitten.com/200/300" />
<img src="http://placekitten.com/300/300" />
</div>
</div>
</div>
<div class="Aligner">
<div class="Aligner-item">
<div class="flex-item">
<img src="http://placekitten.com/100/300" />
<img src="http://placekitten.com/200/200" />
</div>
</div>
</div>
推荐阅读
- pdf - 如何使用 wkhtmltopdf 创建用于 Kindle Direct Publishing 的 PDF
- jenkins - Jenkins 插件开发 - 如何以用户身份登录
- php - 为什么不能使用 PDO 访问特定的数据库,但可以使用没有数据库名称的 mysqli?(使用 devserver/phpmyadmin)?
- linux - PPS:如何从 PPS 调整系统时钟?
- qt - 如何手动将 Qt .rep 复制到 .h,然后将它们 moc 到 .cpp
- python - 如何在带有 Django 的 HTML 中跳过逻辑并继续循环
- ios - UIView 扩展中用于自定义枚举案例的新属性
- javascript - 当两个参数都只是构造函数名称时, setPrototypeOf(...) 有什么好处?
- javascript - 如何在 d3.js 中创建多折线图,其中每条线的数据都是从单独的 csv 中提取的?
- discord.js - 如何制作谷歌命令