首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有背景图像url的CSS变量

带有背景图像url的CSS变量
EN

Stack Overflow用户
提问于 2017-01-20 02:21:45
回答 2查看 29.9K关注 0票数 29

我是不是误解了css变量的功能?我正在尝试将一个背景图片url传递给一个变量,如下所示:当我传递一些简单的东西时,它似乎工作得很好,比如颜色等等。

代码语言:javascript
复制
:root {
  --slide-1: url(/static/images/slideshow/slide1.jpg) ;
  --slide-2: url(/static/images/slideshow/slide2.jpg) ;
  --slide-3: url(/static/images/slideshow/slide3.jpg) ;
  --slide-4: url(/static/images/slideshow/slide4.jpg) ;
  --slide-5: url(/static/images/slideshow/slide5.jpg) ;
}

//and then

.jumbotron > .jumbotron-slideshow:nth-child(1) { 
  background-image: var(--slide-1); 
}

.jumbotron > .jumbotron-slideshow:nth-child(2) {
  animation-delay: 6s;
  background-image: var(--slide-2);
}

.jumbotron > .jumbotron-slideshow:nth-child(3) {
  animation-delay: 12s;
  background-image: var(--slide-3);
}

.jumbotron > .jumbotron-slideshow:nth-child(4) {
  animation-delay: 18s;
  background-image: var(--slide-4);
}

.jumbotron > .jumbotron-slideshow:nth-child(5) {
  animation-delay: 24s;
  background-image: var(--slide-5);
}
EN

回答 2

Stack Overflow用户

发布于 2017-04-14 07:48:10

这是Chrome中的bug,代码在火狐中运行良好。

现在,您必须坚持在var()中使用绝对URL。

票数 10
EN

Stack Overflow用户

发布于 2019-07-24 20:24:24

这是一个bug,但现在它可以工作了。?

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41748998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档