【发布时间】:2018-05-18 15:27:03
【问题描述】:
目前,我有一个图像幻灯片标题没有相对于父容器定位自身的问题。这可能是 DIV 浮动的简单修复,但对于我的生活,我无法弄清楚。问题是文本不在包含图像的容器的约束范围内;因此,在调整网页大小时会发生不同的转换(基本上会移出页面的可见区域)。我希望将容纳文本的容器的高度设置为父容器(容纳图像的容器)的高度,然后再将其格式化为位于页面中心图像的顶部 1/3。文本基于 UL,并在列表中的项目之间转换为图像上的叠加层。
This is the code on Codepen.当 CSS 转换时看到的文本(例如使用的白色背景)都在 .container DIV 的边界之外(我希望将文本限制到的带有阴影的 UL。
任何帮助将不胜感激。
这是 HTML
<div class="container" >
<ul class="imageBanner">
<li>
<span>Image 01</span>
<div>
<h2>Ahoy.</h2>
</div>
</li>
<li><span>Image 02</span>
<div>
<h2>Welcome.</h2>
</div></li>
<li><span>Image 03</span>
<div>
<h2>Bonjour.</h2>
</div></li>
</ul>
</div>
这是CSS
.container {
/* Full height*/
height: 100%;
box-shadow: 0px 8px 5px #888888;
background:#ccc;
}
/* Image Slideshow Banner */
.imageBanner li span {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
color: transparent;
background-size: cover;
background-position: 30%;
background-repeat: none;
opacity: 0;
z-index: 0;
animation: imageAnimation 18s linear infinite 0s;
}
.imageBanner li div {
z-index: 1;
position: absolute;
top:0px;
width: 100%;
text-align: center;
opacity: 0;
animation: titleAnimation 18s linear infinite 0s;
}
.imageBanner li div h2 {
font-family:Calibri, Arial, sans-serif;
background: #fff;
font-size: 7em;
color: rgb(46,105,163);
line-height: 6em;
}
.imageBanner li:nth-child(1) span {
background-image: url('./images/iron_giant.jpg');
}
.imageBanner li:nth-child(2) span {
background-image: url("./images/lonely_island.jpg");
animation-delay: 6s;
}
.imageBanner li:nth-child(3) span {
background-image: url("./images/mountain_range.jpg");
animation-delay: 12s;
}
.imageBanner li:nth-child(2) div {
animation-delay: 6s;
}
.imageBanner li:nth-child(3) div {
animation-delay: 12s;
}
@keyframes imageAnimation {
0% { opacity: 0; animation-timing-function: ease-in; }
8% { opacity: 1; animation-timing-function: ease-out; }
17% { opacity: 1 }
35% { opacity: 0 }
100% { opacity: 0 }
}
@keyframes titleAnimation {
0% { opacity: 0 }
8% { opacity: 1 }
17% { opacity: 1 }
35% { opacity: 0 }
100% { opacity: 0 }
}
【问题讨论】: