html - 如何将一张图像放在另一张图像上?
问题描述
我有这个 HTML 布局:
<div class="profile-img">
<img src="https://via.placeholder.com/150">
</div>
有了这个 CSS
.profile-img, .profile-img > img {
width: 160px;
height: 160px;
border-radius: 50%;
}
这是我的 JS 小提琴:
https://jsfiddle.net/wsho4vq7/
我现在要做的是将附加图像添加到圆形图像的右下角......我将如何去做并使右下角的图像可点击?
解决方案
我建议将您的次要图像作为.profile-img
. 从这里,给出.camera
图像position: absolute
和父.profile-img
元素position: relative
。bottom
这将允许您通过使用and将子元素定位在右下角right
。在我的示例中,我都选择了15px
两者,但可以随意调整以适应。您也可以使用负值!
要使图像可点击,您可以使用cursor: pointer
(以增加效果)以及一些自定义 JavaScript 事件处理程序,或者如果您想重定向,只需将其包装<img>
在标签中。<a>
这可以在下面看到:
.profile-img,
.profile-img > .placeholder {
width: 160px;
height: 160px;
border-radius: 50%;
position: relative;
}
.camera {
position: absolute;
bottom: 15px;
right: 15px;
}
<div class="profile-img">
<img class="placeholder" src="https://via.placeholder.com/150">
<a href="https://www.google.com">
<img class="camera" src="https://i.stack.imgur.com/lPMJf.png">
</a>
</div>
推荐阅读
- python - Python 在没有 Pandas 的情况下打印 x 行和列
- apk - 为什么在使用 apktool 构建 apk 文件时会出现 brut.androlib.AndrolibException-error?
- node.js - Node JS 创建嵌套目录
- docker - 为了安全起见,我应该以非 root 身份在 docker 容器中运行东西吗?
- html - 尝试在博客标题中添加 H1,我该如何添加?
- python - 改进 Python 中的 HashSet 设计
- html - 页眉和页脚在 375 和 320 移动视图向左推,但其他一切都好吗?
- time - fork() 是否会创建一个具有不同突发时间和内存要求的子进程
- swift - ScrollView 嵌套在 TabView 重置位置以在更改选项卡时开始
- r-markdown - rmarkdown 风格的 python 块