html - 如何在 HTML 中将图像居中放在另一个图像上
问题描述
<tr>
<td style='text-align: center;'>
<img style='height: 50px;width:50px;' src='./images/01.png' >
<img style='height: 15px;width:15px;'src='./images/02.png' >
</td>
</tr>
如何将 02.png 定位到 01.png 的中心?对于 1 层。
解决方案
您可以在父级(td 元素)中使用相对位置,在图像 2 样式中使用绝对位置。
#col {
position: relative;
}
#img-1 {
width: 50px;
height: 50px;
}
#img-2 {
width: 20px;
height: 20px;
position: absolute;
right: 16px;
top: 14px;
}
<table>
<tr>
<td id="col">
<img id="img-1" src="img-1.jpg">
<img id="img-2" src="img-2.jpg">
</td>
</tr>
</table>
推荐阅读
- web-component - 聚合物和 SQL 数据库
- javascript - 递归函数 JavaScript
- perl - 使用 -e 标志检查文件或目录是否存在 [perl]
- performance - 如何查看 Jenkins 任务/构建/项目持续时间的历史图表?
- arrays - 将给出的答案解释为两个数组
- asp.net-mvc - 在 NopCommerce 中更改 Razor 视图后,它们不会更新
- css - 如何让 base64 编码的 SVG 过滤器在 Firefox 以外的其他浏览器中工作?
- javascript - 将值从一个属性移动到另一个属性
- jquery - id 在视口中时突出显示菜单项
- javascript - 带有组件的 Google 地图地理编码请求 - 语法