繁体   English   中英

CSS-即使将滑块设置为100%宽度,响应式推荐滑块文本也不会调整大小

[英]CSS - Responsive Testimonial Slider text is not resizing even tho the slider is set at 100% width

即使将滑块的所有其他类别设置为100%宽度,但响应式见证滑块文本也不会调整大小,并且div也都设置为100%,但是由于某些原因,当我调整屏幕大小时,它会变大并在屏幕上被截断。

JSFiddle演示在这里: https ://jsfiddle.net/fjkL61va/


HTML


<div id="slides" style="background:red;">

  <ul>

    <li class="slide">
        <h2>"m gravida elit vitae volutpat ornare. Morbi pellentesque vehicula urna ut sagittis. Nunc euismod fermentum vehicula."</h2>
    </li>

    <li class="slide">
      <h2>"m gravida elit vitae volutpat ornare. Morbi pellentesque vehicula urna ut sagittis. Nunc euismod fermentum vehicula."</h2> 
    </li>

    <li class="slide">
        <h2>"m gravida elit vitae volutpat ornare. Morbi pellentesque vehicula urna ut sagittis. Nunc euismod fermentum vehicula."</h2>
    </li>

  </ul>

</div>


  <div id="buttons">

    <a id="prev" href="#">&lt;</a>

    <a id="next" href="#">&gt;</a>

  </div>

的CSS


#slides {
    width: 100%;
    height: auto;
    overflow: hidden;
    position: relative;
  }

  #slides ul {
    width: 100%;
    height: auto;
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
  }

  #slides li {
    width: 100%;
    height: auto;
    float: left;
    text-align: center;
    position: relative;
  }

  #prev {
    float: left;
    font-size: 300%;

  }
  #next {
    float: right;
    font-size: 300%;

  }

Java脚本


       $(document).ready(function () {
  //rotation speed and timer
  var speed = 5000;

  var run = setInterval(rotate, speed);
  var slides = $('.slide');
  var container = $('#slides ul');
  var elm = container.find(':first-child').prop("tagName");
  var item_width = container.width();
  var previous = 'prev'; //id of previous button
  var next = 'next'; //id of next button
  slides.width(item_width); //set the slides to the correct pixel width
  container.parent().width(item_width);
  container.width(slides.length * item_width); //set the slides container to the correct total width
  container.find(elm + ':first').before(container.find(elm + ':last'));
  resetSlides();


  //if user clicked on prev button

  $('#buttons a').click(function (e) {
    //slide the item

    if (container.is(':animated')) {
      return false;
    }
    if (e.target.id == previous) {
      container.stop().animate({
        'left': 0
      }, 1500, function () {
        container.find(elm + ':first').before(container.find(elm + ':last'));
        resetSlides();
      });
    }

    if (e.target.id == next) {
      container.stop().animate({
        'left': item_width * -2
      }, 1500, function () {
        container.find(elm + ':last').after(container.find(elm + ':first'));
        resetSlides();
      });
    }

    //cancel the link behavior      
    return false;

  });

  //if mouse hover, pause the auto rotation, otherwise rotate it  
  container.parent().mouseenter(function () {
    clearInterval(run);
  }).mouseleave(function () {
    run = setInterval(rotate, speed);
  });


  function resetSlides() {
    //and adjust the container so current is in the frame
    container.css({
      'left': -1 * item_width
    });
  }

});
//a simple function to click next link
//a timer will call this function, and the rotation will begin

function rotate() {
  $('#next').click();
}

您可以对文本使用媒体查询。

暂无
暂无

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

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