css - 如何使用双封面设置“背景尺寸”?
问题描述
我想设置一个background-size
双盖像:
background-size:cover*200%; // not working
background-size:calc(cover*200%); // not working
background-size:calc(cover); // not working
有可能做到吗?
我不想用javascript来做。多谢。
解决方案
想法是考虑应用封面的另一个元素,并使这个元素大两倍。例如,您可以使用伪元素。
我保留溢出以查看结果:
.box {
width:150px;
height:150px;
border:2px solid;
margin:100px;
position:relative;
/* overflow:hidden;*/
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:50%;
left:50%;
background:var(--img) center/cover no-repeat;
width:200%;
height:200%;
transform:translate(-50%,-50%);
border:2px solid red;
}
<div class="box" style="--img:url(https://picsum.photos/200/350?image=1069)"></div>
与规模相同的想法:
.box {
width:150px;
height:150px;
border:2px solid;
margin:100px;
position:relative;
/* overflow:hidden;*/
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
background:var(--img) center/cover no-repeat;
width:100%;
height:100%;
transform:scale(2);
border:2px solid red;
}
<div class="box" style="--img:url(https://picsum.photos/200/350?image=1069)"></div>
推荐阅读
- ruby-on-rails - Rails 服务器问题
- pytorch - CUDA的Pytorch检测
- macos - OS X 10.15 (Catalina) 上的 GDB 在第一次执行时卡住
- r - 当 x 具有几何分布时,如何使用 sample() 函数从 x 生成 n 个随机变量?
- xcode - 如何更改 Xcode 项目,这样我就不必在 SUDO 模式下运行它
- sql-server - 出现“无法打开访客会话”错误
- xamarin - 属性“内容”设置不止一次 - XAML
- python - KeyError:使用带有布尔值的 get_loc 时为真
- java - 如何使用 Elasticsearch API ScriptQueryBuilder
- angular - 如何在我的 Angular 应用程序中调试 node_module?