【问题标题】:Why is my text not next to my thumbnail in Bootstrap 4 and Slick?为什么我的文本不在 Bootstrap 4 和 Slick 中的缩略图旁边?
【发布时间】:2017-12-28 00:28:39
【问题描述】:

我尝试将 Slick 与我的 Bootstrap 4 网站集成,但这让我很难过。我的目标是从缩略图中定位我的文本。 不知何故,它在缩略图下方移动。知道为什么吗?

我的问题

HTML

<div class="row">
    <div class="col-12 tb-items">
        <div class="row tb__item">
            <div class="col-5">
                <img class="tb__thumbnail" src="{% static "img/placeholders/fb.jpg" %}">
            </div>
            <div class="col-7">
                <a href="#">Book</a>
                <h3><a href="#">1 The Everlast Notebook</a></h3>
                <p>One smart, reusable notebook to last the rest of your life? That's not magic, that's the Everlast.</p>
                <p>by <a href="#">Andrew Noah</a></p>
                <div class="tb__votes">
                    <b>123123123</b><br>votes
                </div>
                <div class="tb__date-created">
                    <b>23</b><br>days ago
                </div>
            </div>
        </div>
    <div class="row tb__item">
        <div class="col-5">
            <img class="tb__thumbnail" src="{% static "img/placeholders/fb.jpg" %}">
        </div>
        <div class="col-7">
            <a href="#">Book</a>
            <h3><a href="#">1 The Everlast Notebook</a></h3>
            <p>One smart, reusable notebook to last the rest of your life? That's not magic, that's the Everlast.</p>
            <p>by <a href="#">Andrew Noah</a></p>
            <div class="tb__votes">
                <b>123123123</b><br>votes
            </div>
            <div class="tb__date-created">
                <b>23</b><br>days ago
            </div>
        </div>
    </div>
</div>
</div>

CSS

.tb__thumbnail {
    width: 100%;
}

JAVASCRIPT

$(function () {
    $('.tb-items').slick({
        arrows: false,
    })

    $('.tb__topic').click(function () {
            $('.tb-items').slick('slickNext')
        }
    )
})

【问题讨论】:

  • 你确定你没有任何其他的 CSS 或 Div 包装这个吗?我觉得没问题codepen.io/anon/pen/VypvRL
  • 别担心,现在就看。一会儿

标签: javascript html css twitter-bootstrap slick.js


【解决方案1】:

我会在ul 中创建您的列,每个.tb__itemli。让我知道你的情况如何?

$(function () {
    $('.tb-items').slick({
        arrows: false,

    })

    $('.tb__topic').click(function () {
            $('.tb-items').slick('slickNext')
        }
    )
})
.tb__thumbnail {
    width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css" rel="stylesheet"/>

<div class="row">
  <div class="col-12 tb-items">
     <ul class="tb-items">
        <li class="tb__item">
          <div class="row">
             <div class="col-5">
               <img class="tb__thumbnail" src="https://images.unsplash.com/photo-1488393660112-976f752342de?dpr=1&auto=format&fit=crop&w=568&h=539&q=60&cs=tinysrgb">
             </div>
             <div class="col-7">
                <a href="#">Book</a>
                <h3><a href="#">1 The Everlast Notebook</a></h3>
                <p>One smart, reusable notebook to last the rest of your life? That's not magic, that's the Everlast.</p>
                <p>by <a href="#">Andrew Noah</a></p>
                <div class="tb__votes">
                  <b>123123123</b><br>votes
                </div>
                <div class="tb__date-created">
                  <b>23</b><br>days ago
                </div>
             </div>
           </div>
       </li>
       <li class="tb__item">
          <div class="row">
             <div class="col-5">
               <img class="tb__thumbnail" src="https://images.unsplash.com/photo-1488393660112-976f752342de?dpr=1&auto=format&fit=crop&w=568&h=539&q=60&cs=tinysrgb">
             </div>
             <div class="col-7">
                <a href="#">Book</a>
                <h3><a href="#">1 The Everlast Notebook</a></h3>
                <p>One smart, reusable notebook to last the rest of your life? That's not magic, that's the Everlast.</p>
                <p>by <a href="#">Andrew Noah</a></p>
                <div class="tb__votes">
                  <b>123123123</b><br>votes
                </div>
                <div class="tb__date-created">
                  <b>23</b><br>days ago
                </div>
             </div>
           </div>
       </li>
    </ul>                 
 </div>
</div>

【讨论】:

  • 太棒了!将&lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt; 用于 HTML 中的幻灯片是否很常见?知道是什么导致了这个问题吗?
  • 我倾向于将它们用于任何幻灯片或旋转木马,尤其是当我将它们放在循环中时。我认为问题是由您在items 上的row 引起的。 Bootstrap 非常棒,但是当您将 rowcontainers 放在 row 中时,您开始得到负填充,导致内部宽度超过 100% - 通常很容易被过度复杂化而忘乎所以网格元素 - 我一直在这样做。无论如何,很高兴它对你有用。
猜你喜欢
  • 2021-01-22
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-12
  • 2021-07-02
  • 2012-07-02
相关资源
最近更新 更多