我有一个使用CSS掩码创建的图像动画,但出于某种原因,max-width: 100%;
上的媒体查询img
属性隐藏/覆盖部分内容图片。如果我删除它,它会正常显示,但图像没有响应。
可在此处找到代码/演示(重新调整结果窗口以重现):http://jsfiddle.net/x2hnomhs/。
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
我实际上已经明白了。希望这就是你要找的东西:
http://jsfiddle.net/x2hnomhs/2/
.logo {
display: block;
max-width: 450px;
width: auto;
margin: 0 auto;
overflow: hidden;
}
.logo a {
display: block;
height: 100%;
width: 100%;
position: relative;
}
.logo a img.logoMask {
position: relative;
z-index: 20;
width: 100%;
display: block;
height: auto;
}
.logo a img.color {
position: absolute;
z-index: 1;
left: 0;
top: 3px;
-webkit-animation: logoColor 15s infinite; /* Chrome, Safari, Opera */
animation: logoColor 15s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes logoColor {
0% {left: 0;}
50% {left: -2500px;}
100% {left: 0;}
}
/* Standard syntax */
@keyframes logoColor {
0% {left: 0;}
50% {left: -2500px;}
100% {left: 0;}
}
答案 1 :(得分:1)
将您height:auto
中的height:100%
更改为@media screen and (max-width: 940px)
片段:
.logo {
display: block;
width: 450px;
margin: 0 auto;
padding-bottom: 40px;
}
.logo a {
display: block;
height: 288px;
overflow: hidden;
width: 450px;
position: relative;
}
.logo a img.logoMask {
position: relative;
z-index: 20;
width: 100%;
height: auto;
}
.logo a img.color {
position: absolute;
z-index: 1;
left: 0;
top: 3px;
-webkit-animation: logoColor 15s infinite; /* Chrome, Safari, Opera */
animation: logoColor 15s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes logoColor {
0% {
left: 0;
}
50% {
left: -2500px;
}
100% {
left: 0;
}
}
/* Standard syntax */
@keyframes logoColor {
0% {
left: 0;
}
50% {
left: -2500px;
}
100% {
left: 0;
}
}
@media screen and (max-width: 940px) {
img {
max-width: 100%;
height: 100%;
}
}
<div class="logo">
<a style="padding-right: 0">
<img src="http://api.marioparra.me/img/api-logo-mask.png" class="logoMask" />
<img src="http://api.marioparra.me/img/api-logo-gradient.png" class="color" />
</a>
</div>
更新:基于OP评论(阐明OP真正想要实现的目标)
由于您希望在所有视口大小中制作相同类型的animation
并在此处使其响应,因此会添加一个代码段(评论已添加以解释更改):
.logo {
display: block;
max-width: 450px;
/* changed from width to max-width */
margin: 0 auto;
padding-bottom: 40px;
overflow: hidden;
/* added this */
}
.logo a {
display: block;
height: 288px;
overflow: hidden;
max-width: 450px;
/* changed from width to max-width */
position: relative;
}
.logo a img.logoMask {
position: relative;
z-index: 20;
width: 100%;
height: auto;
}
.logo a img.color {
position: absolute;
z-index: 1;
left: 0;
top: -50%;
/* changed from 3px to -50% */
-webkit-animation: logoColor 5s infinite;
/* Chrome, Safari, Opera */
animation: logoColor 5s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes logoColor {
0% {
left: 0;
}
50% {
left: -2500px;
}
100% {
left: 0;
}
}
/* Standard syntax */
@keyframes logoColor {
0% {
left: 0;
}
50% {
left: -2500px;
}
100% {
left: 0;
}
}
/*removed uncessary media queries because you are using now max-width in your parent container , with that your img {width:100%} it is enough to make it responsive. */
@media screen and (max-width: 480px) {
.logo a img.color {
top: -60%
}
}
@media screen and (max-width: 360px) {
.logo a img.color {
top: -72%
}
}
<div class="logo">
<a style="padding-right: 0">
<img src="http://api.marioparra.me/img/api-logo-mask.png" class="logoMask" />
<img src="http://api.marioparra.me/img/api-logo-gradient.png" class="color" />
</a>
</div>