gpt4 book ai didi

html - 部分图像覆盖在响应式 View 中

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:10 25 4
gpt4 key购买 nike

我有一个使用 CSS 掩码创建的图像动画,但出于某种原因,我的媒体查询的 max-width: 100%; 属性在 img 上隐藏/覆盖图像的一部分。如果我删除它,它会正常显示,但随后图像没有响应。

可在此处找到代码/演示(调整结果窗口大小以重现):http://jsfiddle.net/x2hnomhs/ .

如有任何帮助,我们将不胜感激。谢谢!

最佳答案

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 真正想要实现的目标)

由于您想在所有视口(viewport)尺寸中制作相同类型的动画并使其响应,这里是一个片段(添加了注释以解释更改):

.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>

关于html - 部分图像覆盖在响应式 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31615196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com