【发布时间】:2018-10-17 10:30:54
【问题描述】:
我正在创建一个博客,并试图在导航栏下方获取一张图片。我有四个使用 css 和 js 滑动的图像。但是,无论我如何尝试,我都无法让图像跨越页面的宽度。我已经尝试了 100% 的宽度、vw 等。没有什么能按我想要的方式工作。这是html和css(记住我一直在玩css)
#stage {
margin: 1em auto;
width: 100%;
height: 292px;
margin-bottom: 40px;
}
#stage a {
position: absolute;
}
#stage a img {
padding: 10px;
border: 1px solid #ccc;
background: #fff;
}
#stage a:nth-of-type(1) {
animation-name: fader;
animation-delay: 4s;
animation-duration: 1s;
z-index: 20;
}
#stage a:nth-of-type(2) {
z-index: 10;
}
#stage a:nth-of-type(n+3) {
display: none;
}
@keyframes fader {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
这里是html
<div id="stage">
<a><%= image_tag "2.jpeg" %></a>
<a><%= image_tag "1.jpeg" %></a>
<a><%= image_tag "3.png" %></a>
<a><%= image_tag "4.jpeg" %></a>
</div>
【问题讨论】:
-
将图像设置为div的背景,然后使用
background-size: cover将其拉伸到div的宽度。您也可以使用background-position: center将其居中。
标签: html css ruby-on-rails