在移动设备上自定义 Bootstrap 5 轮播(多个项目,但不在一行)
P粉763662390
P粉763662390 2023-09-05 11:53:56
[CSS3讨论组]
<p>我在尝试自定义移动设备上的轮播布局时遇到问题。 我希望它在移动设备上显示轮播的每一项,而不是只显示一项,但在尝试使用一些 CSS 和 JS 之后,尤其是使用 <code>display</code> <code>float</code> 或<code>max-witdh</code> 我刚刚开始认为这是不可能的,或者我不知道在哪里查看/查看错误的位置/属性。 我加入了两张图片,这样你们就可以看到我想要实现的目标。</p> <p>我想要实现的目标: </p> <p>我有什么: </p> <p>示例 html 代码是非常基本的代码,我不包括 CSS,因为这只是出于设计目的。</p> <pre class="brush:php;toolbar:false;">&lt;div id=&quot;solutions-carousel&quot; class=&quot;carousel slide d-block d-md-none&quot;&gt; &lt;div class=&quot;carousel-inner&quot;&gt; &lt;div class=&quot;carousel-item active&quot;&gt; &lt;a href=&quot;#&quot; class=&quot;img-link&quot;&gt;&lt;img src=&quot;./img.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div class=&quot;carousel-item&quot;&gt; &lt;a href=&quot;#&quot; class=&quot;img-link&quot;&gt;&lt;img src=&quot;./img.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div class=&quot;carousel-item active&quot;&gt; &lt;a href=&quot;#&quot; class=&quot;img-link&quot;&gt;&lt;img src=&quot;./img.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div class=&quot;carousel-item active&quot;&gt; &lt;a href=&quot;#&quot; class=&quot;img-link&quot;&gt;&lt;img src=&quot;./img.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div class=&quot;carousel-item active&quot;&gt; &lt;a href=&quot;#&quot; class=&quot;img-link&quot;&gt;&lt;img src=&quot;./img.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div class=&quot;carousel-indicators&quot;&gt; &lt;button type=&quot;button&quot; data-bs-target=&quot;#solutions-carousel&quot; data-bs-slide-to=&quot;0&quot; class=&quot;active&quot; aria-current=&quot;true&quot; aria-label=&quot;Slide 1&quot;&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; data-bs-target=&quot;#solutions-carousel&quot; data-bs-slide-to=&quot;1&quot; aria-label=&quot;Slide 2&quot;&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; data-bs-target=&quot;#solutions-carousel&quot; data-bs-slide-to=&quot;2&quot; aria-label=&quot;Slide 3&quot;&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; data-bs-target=&quot;#solutions-carousel&quot; data-bs-slide-to=&quot;3&quot; aria-label=&quot;Slide 3&quot;&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; data-bs-target=&quot;#solutions-carousel&quot; data-bs-slide-to=&quot;4&quot; aria-label=&quot;Slide 3&quot;&gt;&lt;/button&gt; &lt;/div&gt;</pre> <p>有什么想法吗?干杯(并对糟糕的英语表示歉意)。</p>
P粉763662390
P粉763662390

全部回复(1)
P粉029057928

我认为类似的问题和案例之前已经在另一个线程中得到了回答。我找到了一些可能对您有帮助的参考资料,我会给您一些链接。 stackoverflow 中的另一个线程

您还可以使用以下 JS 代码:

$('.multi-item-carousel').carousel({
  interval: false
});

// for every slide in carousel, copy the next slide's item in the slide.
// Do the same for the next, next item.
$('.multi-item-carousel .item').each(function(){
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));
  
  if (next.next().length>0) {
    next.next().children(':first-child').clone().appendTo($(this));
  } else {
    $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
  }
});

免责声明:这些答案/代码片段不是我的。我从 Maurice melchers 的 https://codepen.io/mephysto/pen/ZYVKRY 得到它

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号