html - 试图将 svg 放在 img 之上
问题描述
我修改了我之前的代码,现在问题如下:我正在尝试将一个 svg 放在一个 img 之上。我只能放置在左上角,顶部:0;并离开:0;当我增加这些值时,svg 会位于容器下方。
.video-container {
position: relative;
display: inline-block;
}
.video-container img {
display: block;
max-width: 100%;
height: auto;
}
.video-container svg {
position: absolute;
top: 1;
left: 0;
}
<div class = "video-container">
<img class = "video" src="./images/play-video.svg" alt="play-video" />
<svg width="190" height="63">
<g>
<rect x="0" y="0" width="190" height="63" fill="blue"/>
<text x="50%" y="50%" fill="white" dominant-baseline="middle" text-anchor="middle">Play Video</text>
</g>
</svg>
</div>
解决方案
您应该为 指定一个单位top
。只是0
不需要单位。
.video-container {
position: relative;
display: inline-block;
}
.video-container img {
display: block;
max-width: 100%;
height: auto;
}
.video-container svg {
position: absolute;
top: 40px;
left: 55px;
}
<div class = "video-container">
<img class = "video" src="https://picsum.photos/300/150" alt="play-video" />
<svg width="190" height="60">
<g>
<rect x="0" y="0" width="190" height="63" fill="blue"/>
<text x="50%" y="50%" fill="white" dominant-baseline="middle" text-anchor="middle">Play Video</text>
</g>
</svg>
</div>
推荐阅读
- flutter - 如何在颤动中显示/渲染 3D 产品文件(http 链接)?
- knime - Knime循环在不同的文件夹中写入csv文件?
- java - 编译使用单个依赖项 jar 文件的简单类时出错
- here-api - HERE SDK如何设置位置更新间隔?
- lucene - Lucene tfidf 没有 idf 的平方?
- node.js - TypeError:无法读取未定义的属性“密码”
- excel - VBA宏与手动过滤结果不同
- android - 什么是开发人员选项的记录器缓冲区大小
- php - Varnish 似乎根本没有缓存页面
- jquery - 父列jquery中的SharePoint 2010级联下拉错误