【发布时间】:2016-10-19 03:40:35
【问题描述】:
我正在尝试转换 background-size 和 background-color。
-
Chrome:
background-size的转换不起作用 - Firefox:两者都运行良好
我还创建了一个fiddle。
.highlight {
display: block;
position: relative;
/*min-height: 800px;*/
min-height: 200px;
background-position: center center;
background-repeat: no-repeat;
/*padding-top: 200px;*/
padding-top: 80px;
/*background-size: cover;*/
}
.highlight:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .25);
content: "";
}
.highlight {
position: relative;
height: 200px;
cursor: pointer;
background-size: auto 110%;
background-position: center center;
-moz-transition: background-size 3s ease;
-webkit-transition: background-size 3s ease;
transition: background-size 3s ease;
}
.highlight:hover {
background-size: auto 130%;
background-color: rgba(0, 0, 0, 0.4);
-moz-transition: background-size 3s ease;
-webkit-transition: background-size 3s ease;
transition: background-size 3s ease;
}
.highlight:before {
content: ' ';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
-moz-transition: background-color 3s ease;
-webkit-transition: background-color 3s ease;
transition: background-color 3s ease;
}
.highlight:hover:before {
background-color: rgba(0, 0, 0, 0.8);
-moz-transition: background-color 3s ease;
-webkit-transition: background-color 3s ease;
transition: background-color 3s ease;
}
<div class="highlight" style="background-image:url(http://cdn2.stillgalaxy.com/ori/2015/06/06/female-doctors-stock-photos-2331433563559.jpg);">
</div>
有人帮我解决这个问题吗?或者可以确定正在破坏这些过渡?
谢谢
【问题讨论】:
-
我怀疑这是因为 bg 图像不在 CSS 中……而是内联样式。
-
当然是:) 你可以在firefox中查看sn-p。
-
@Paulie_D 我也尝试在 css 中使用 background-size,但在 Chrome 中不起作用,无论如何我需要在代码中使用 background-img
-
你不能为
auto制作动画(至少你应该不能)...你必须使用一个值。 -
你可以使用
transform:scale(),在chrome中效果更好
标签: css css-transitions transition background-size