【问题标题】:Make slider full width, but center contents使滑块全宽,但内容居中
【发布时间】:2012-12-07 06:11:50
【问题描述】:

我正在玩 http://www.slidesjs.com/ 滑块。试图使其全宽,但使当前幻灯片 (slidescontent) 全宽,但在容器 (slidescenter) 内有一个 div,使其内容保持居中并设置宽度,这是我使用的代码:

<!doctype html>
    <head>
        <title>Title</title>

        <style type="text/css" media="screen">
            .slides_container {
                width:100%;
                height:270px;
            }
            .slides_container div {
                width:100%;
                height:270px;
                display:block;
            }
           .slidescontent {width:100%;}
           .slidescenter {width:990px;}
        </style>

        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script src="slides.js"></script>

        <script>
            $(function(){
                $("#slides").slides();
            });
        </script>
    </head>
    <body>
        <div id="slides">
            <div class="slides_container">
                <div class="slidescontent">
                  <div class="slidescenter">
                    Text 1
                  </div>
                </div>
                <div>
                    Text 2
                </div>
                <div>
                    <img src="http://placehold.it/570x270">
                </div>
                <div>
                    <img src="http://placehold.it/570x270">
                </div>
            </div>
        </div>
    </body>

【问题讨论】:

    标签: jquery html css


    【解决方案1】:

    我建议使用CycleSlidesjs 正在添加不需要的 html... 导致一些问题

    我在这个网站上做了一个居中的幻灯片:http://celebrationsnetwork.co.nz

    通过使主容器设置宽度和居中(使用边距)来做到这一点

    #slides {
        width: 570px;
        height: 270px;
        margin: 0 auto;
        overflow: hidden;
    }
    

    让幻灯片也设置宽度:

    #slides .slide {
        width: 570px;
        height: 270px;
    }​
    

    我在 Jsfiddle 上解决了你的问题:http://jsfiddle.net/3q8cX/4

    有什么问题吗?

    【讨论】:

      【解决方案2】:

      由于无法实际使用 slides.js(因为它指的是本地机器/服务器上的副本),所以很难判断发生了什么。您是否尝试过以标准方式将 .slidescenter 居中?

      .slidescenter {
        width: 990px;
        margin: 0 auto;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-09-16
        • 2013-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多