【发布时间】:2016-09-06 10:21:24
【问题描述】:
你好! 我使上面的图像响应 320x767 像素的屏幕分辨率。我的代码工作正常。
但是,我有一个问题,在图像上创建的阴影效果没有响应。我想要的是随着我的图像变小,阴影也应该随着图像高度变小。或者它应该表现得响应 我该怎么办?
html
<body>
<div class=" background-img">
<img src="img/learning.jpg" class="img-responsive">
<div class="overlay">
</div>
</div>
</body>
CSS
.background-img{
max-width: 100%;
height: auto;
}
.overlay{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
background-color: black;
opacity: 0.5;
}
@media only screen and (min-width:320px) and (max-width:767px){
.background-img{
width: 426px !important;
height: 320px !important ;
}
.overlay{
position:fixed;
top: 0;
left: 0;
width: 30% !important;
height: 25%!important;
z-index: 10;
position: absolute;
background-color: black;
opacity: 0.5;
}
【问题讨论】:
-
删除
position:fixed绝对会做并将您的宽度和高度设置为 100% 还将position:relative添加到 background-img -
尝试使用相对位置。
-
@winresh24 哪个宽度和高度应该是 100%?并且在媒体查询中背景图像需要设置在相对位置?
-
等我给你做个小提琴
标签: javascript html css media-queries