【发布时间】:2015-12-09 13:37:10
【问题描述】:
我在主页上有一个滑块,在其他静态页面上有其他大型英雄图像。所有 100% 屏幕宽度。在较小的屏幕上,其他英雄图像保持比我的滑块图像更大(高度)。所有图像高度都设置为自动。
我需要滑块图像不只是根据全宽进行缩放。我不在乎它们是否被截断,移动设备上的图像高度变得太小了。似乎区别在于背景大小:封面和填充。但是当我尝试它时它不起作用,我要么把它放在错误的元素上,要么因为滑块宽度为 500% 而弄乱了它?
英雄图像是这样构建的:
<div class="hero" style="background-image: url('/images/static/shop/hero_necklaces.jpg');">
<div class="hero-text">
<h1>Jewelry</h1>
</div>
</div>
@media (max-width: 480px)
.hero {
padding-top: 60px;
padding-bottom: 60px;
}
@media (max-width: 650px)
.hero {
padding-top: 90px;
padding-bottom: 90px;
}
.hero {
width: 100%;
height: auto;
padding-top: 140px;
padding-bottom: 140px;
display: table;
vertical-align: middle;
-webkit-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
滑块是这样构建的:
<div id="captioned-gallery" class="homepage-slider">
<figure class="slider">
<figure>
<a href="${request.contextPath}/category/Jewelry"><img src="${request.contextPath}/images/static/home/header_hero1.jpg" alt="The 2015 Fall Collection"></a>
<!--<figcaption class="hero-text">Sample Text 1</figcaption>-->
</figure>
<figure>
<a href="${request.contextPath}/jsp/static/joinUs.jsp"><img src="${request.contextPath}/images/static/home/header_hero2.jpg" alt="Get Paid to Share the Hope"></a>
</figure>
<figure>
<a href="${request.contextPath}/jsp/static/impact.jsp"><img src="${request.contextPath}/images/static/home/header_hero3.jpg" alt="Handcrafted Artisan Made"></a>
</figure>
<figure>
<a href="${request.contextPath}/category/Jewelry"><img src="${request.contextPath}/images/static/home/header_hero1.jpg" alt="The 2015 Fall Collection"></a>
</figure>
</figure>
</div>
div#captioned-gallery {
width: 100%;
overflow: hidden;
}
.homepage-slider {
padding-bottom: 115px;
}
figure { margin: 0; }
@-webkit-keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
100% { left: -300%; }
}
@keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
100% { left: -300%; }
}
figure.slider {
position: relative;
width: 500%;
font-size: 0;
-webkit-animation: 40s slidy infinite;
animation: 40s slidy infinite;
}
figure.slider figure {
width: 20%;
height: auto;
display: inline-block;
position: inherit;
}
figure.slider img {
width: 100%;
height: auto;
margin: 0px;
}
【问题讨论】:
-
制作宽度为 500% 的对象背后的逻辑是什么?