简体   繁体   English

Flexslider不会显示第一张幻灯片后的标题

[英]Captions after 1st slide doesnt show for flexslider

I am a newbie in coding and I am trying to add caption with transition to FlexSlider. 我是编码方面的新手,我尝试添加字幕并过渡到FlexSlider。 It works for the 1st slide but for the slides after it won't show. 它适用于第一张幻灯片,但不适用于之后的幻灯片。 Maybe css alone is not enough to handle that? 也许仅靠CSS不足以解决这个问题? It'd be great if someone can show me how it can be done with js if it's necessary. 如果有人可以告诉我如何在必要时使用js来完成,那就太好了。 Thanks a lot! 非常感谢!

Link to jsfiddle: https://jsfiddle.net/ghLm7rL5/1/ 链接到jsfiddle: https ://jsfiddle.net/ghLm7rL5/1/

The code: 编码:

  $(window).load(function(){ $('.flexslider').flexslider({ animation: "slide", directionNav: false, animationLoop: false }); }); 
 .flexslider .slides .flex-caption{ position: absolute; background: rgba(0,0,0,0.75); color: white; padding: 10px 20px; opacity: 0; bottom: 0; left: -30%; -webkit-transition: all 0.6s ease; -moz-transition: all 0.6s ease; -o-transition: all 0.6s ease; } .flexslider .slides li:hover .flex-caption{ opacity: 1; left: 0;} 
 <div class="flexslider"> <ul class="slides"> <li> <a href="#" rel="lightbox" title="Some Title"> <img src="images/graphic_design_thumb1.png" alt="graphic_design_thumb1"/></a> <div class="flex-caption">Caption1</div></li> <li><a href="#" rel="lightbox" title="Some Title"> <img src="images/graphic_design_thumb2.png" alt="graphic_design_thumb2"/></a> <div class="flex-caption">Caption2</div></li> </ul> </div> 

CSS 的CSS

.slides li{
    position:relative;
}

.flexslider .slides .flex-caption{
    position: absolute; 
    background: rgba(0,0,0,0.75); 
    color: white; 
    padding: 10px 20px; 
    opacity: 0;
    bottom: 0; 
    left: -30%;
  -webkit-transition: all 0.6s ease;
  -moz-transition:    all 0.6s ease;
  -o-transition:      all 0.6s ease;
}

.flexslider .slides li:hover .flex-caption{  opacity: 1;  left: 0;}

Use the above CSS and it will work since your position:absolute for the caption you need to have a poition:relative for it's parent div so that it takes it width and shows else it will be show at the screen width which is nothing but the image1's width left side 使用上面的CSS,它将从您的position:absolute变为可用,因为您需要具有poition:relativecaption ,因为它是其父div,因此它将采用它的宽度并显示其他内容,并且将以屏幕宽度显示,除了image1的左侧宽度

DEMO 演示

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

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