html - 相对于图像定位元素
问题描述
我正在尝试相对于主图像定位图像 - 其余图像应位于主图像的左侧、右侧和顶部。
<div class="top">
<img class="top__position" src="https://place-hold.it/300x150" alt="">
<div class="top__winner"><img src="https://place-hold.it/80x80" alt=""></div>
<div class="top__winner"><img src="https://place-hold.it/80x80" alt=""></div>
<div class="top__winner"><img src="https://place-hold.it/80x80" alt=""></div>
</div>
我在执行这项任务时遇到了困难 - 我将相对位置放在 top__position 类上,将绝对位置放在 top__winner 和 top 上:
.top__winner:nth-of-type(1) {
position: absolute;
top: 10px;
left: 20px;
}
解决方案
我把相对位置放在 top__position
你需要穿上position: relative
,.top
不是.top__position
。
编辑:
position: absolute
绝对定位(即服从top
、left
、bottom
、right
属性)一个元素相对于它最近的定位(relative
、absolute
或fixed
)祖先。
推荐阅读
- c - 如何生成唯一的文件名?
- php - 使用 PHP 从本地服务器复制文件夹
- ios - 将行插入 UITableView 的顶部会导致行向下移动,从而导致动画效果不佳
- sql-server - 从 Rails 查询转换 SQL Server 日期格式
- r - 绘制缺少日期范围 R 的时间序列
- bazel - 扩展 Bazel 缓存服务器的最佳方法?
- php - 如何修复 yum install php-mysqli 错误
- c++ - 在链表中添加字符串的简单方法
- polymer - 无法查询 dom 重复中的元素以设置单选按钮默认值
- automation - Automation Anywhere Citrix 插件