简体   繁体   English

为什么我的字幕没有显示在滑块图像的中心

[英]why my captions are not showing at the center of slider image

i am trying to create my slider by using css animation properties.我正在尝试使用 css 动画属性创建我的滑块。 for this i have created slider which is working but when i tried to add captions its working too but caption are showing below the slider images not at center of the images even i added absolute position.为此,我创建了正在运行的滑块,但是当我尝试添加标题时,它也可以正常工作,但是即使我添加了绝对位置,标题也显示在滑块图像下方而不是图像的中心。 here is my code.这是我的代码。 i also gave relative position to its parent div but still not working我也给了它的父 div 的相对位置,但仍然没有工作

 *{ margin: 0; padding: 0; } #fullwrapper{ width: 100%; height: auto; } /*=========================Slider Style======================*/ @keyframes slidy { 0% { left: 0%; } 20% { left: 0%; } 25% { left: -100%; } 45% { left: -100%; } 50% { left: -200%; } 70% { left: -200%; } 75% { left: -300%; } 95% { left: -300%; } 100% { left: -400%; } } @keyframes caps { 0% { left: 0%; float: none; } 20% { left: 0%; float: none;} 25% { left: -100%; float: none;} 45% { left: -100%; float: none;} 50% { left: -200%; } 70% { left: -200%; } 75% { left: -300%; } 95% { left: -300%; } 100% { left: -400%; } } #slider { overflow: hidden; } #slider figure img { width: 20%; float: left; } #slider figure { position: relative; width: 500%; margin: 0; left: 0; text-align: left; font-size: 0; animation: 30s slidy infinite; } #captions{ position: absolute; top: 50%; left: 50%; width: 500%; animation: 30s caps infinite; } .caption{ width: 20%; float: left; font-size: xx-large; font-weight: bold; color: red; font-variant: small-caps; } /*=========================Slider Style======================*/ #navbar{ width: 100%; height: 40px; background-color: transparent; position: absolute; top: 0; }
 <base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/"> <div id="fullwrapper"> <!-- Start of Full Body Wrapper--> <div id="header"> <!-- Start of of Header--> <div id="slider"> <figure> <img src="austin-fireworks.jpg" alt> <img src="taj-mahal_copy.jpg" alt> <img src="ibiza.jpg" alt> <img src="ankor-wat.jpg" alt> <img src="austin-fireworks.jpg" alt> </figure> <div id="navbar"> <nav> <a href="">Home</a> </nav> </div> <figure id="captions"> <span class="caption">some caption text 1</span> <span class="caption">some caption text 2</span> <span class="caption">some caption text 3</span> <span class="caption">some caption text 4</span> <span class="caption">some caption text 5</span> </figure> </div> </div><!-- End of Header--> </div> <!-- End of Full Body Wrapper-->

I solved it by myself.我自己解决了。 I wrapped the caption div in one other div then I set it to use absolute position and it is working fine.我将标题 div 包裹在另一个 div 中,然后将其设置为使用绝对位置,并且工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM