html - 如何将一张图片显示在另一张图片上作为背景?
问题描述
我想将一个图像作为另一个图像的背景(它将是相同的图像)。这仅适用于移动版网站。我尝试了不同的位置和显示组合,但它不起作用,这是我所能得到的:
这就是我的 Vue 代码的样子:
<div class="img-big">
<img
v-if="productCard.file"
:src="`${productCard.file}`"
:alt="productCard.altText || productCard.text"
class="blur-background-img"
>
<img
v-if="productCard.file"
:src="
`${productCard.file}`
"
:alt="productCard.altText || productCard.text"
/>
</div>
这是scss代码:
.img-big {
img {
display: block;
margin: 0px auto;
@media only screen and (max-width: 420px) {
z-index: 2;
width: 70%;
top: 0;
}
}
.blur-background-img {
z-index: 1;
filter: blur(8px);
margin: 0;
width: 100%;
}
}
我知道唯一可以正常工作的是z-index
,但我需要将一张图像(不模糊)放在另一张图像(模糊,作为背景)上
解决方案
用于position: relative
模糊图像和position: absolute
另一张图像,以便可以相对于模糊图像定位。
#outerCircle {
position: relative;
width: 42vw;
height: 42vw;
margin: auto;
border-radius: 50%;
border: 4px solid rgb(255, 62, 62);
background-color: rgb(253, 133, 133);
user-select: none;
}
#styleCircle {
position: absolute;
width: 16vw;
height: 16vw;
text-align: center;
padding: 0%;
top: 10%;
/*Used to reposition*/
left: 10%;
/*Used to reposition*/
border-radius: 50%;
border: 3px solid black;
background-color: rgb(255, 233, 35);
}
<div id="outerCircle">
<div id="styleCircle"></div>
</div>
推荐阅读
- node.js - 在 Windows 上使用 npm run/yarn run 本地安装的可执行依赖项失败
- r - 从数据框中收集列和行中具有相同名称的值
- c# - 使用 VersionOne .Net SDK 建立/测试连接
- java - 为什么在 JBoss7.1.EAP 中加载 applicationContext 时出现 java.lang.NoSuchMethodError
- xml - 使用未知前缀更改 XSLT 中的命名空间
- java - 在我的 Spring Boot 应用程序中,哪里可以关闭 Lettuce Redis 连接?
- google-apps-script - 创建一个按钮,将单元格文本的字体颜色在黑色和白色之间切换,与当前指向的单元格相邻
- laravel - laravel 如何首先重定向到公用文件夹?
- lxd - LXD 的 snap 包版本在哪里存储容器?
- python - Pyspark - 具有重置条件的累积和