我正在使用bootstrap 4.我使用
创建了第二个导航栏<div class="nav-active-border b-danger bottom">
<ul class="nav nav-active-border b-warning flex-row">
<li class="nav-item">Link 1</li>
<li class="nav-item">Link 2</li>
<li class="nav-item">Link 3</li>
<li class="nav-item">Link 4</li>
<li class="nav-item">Link 5</li>
<li class="nav-item">Link 6</li>
<li class="nav-item">Link 7</li>
<li class="nav-item">Link 8</li>
<li class="nav-item">Link 9</li>
</ul>
</div>
然而,在移动设备上显示两行中有多个项目。如何使用仅针对移动布局的指示器在移动设备上为这些导航项创建水平滚动。它在桌面和笔记本电脑上显示完美
我试图在谷歌上实现同样的目标 https://www.google.co.in/intl/en/about/products/
答案 0 :(得分:0)
我使用flexbox实用程序类使用Bootstrap 4创建了类似的东西。
一个小jQuery用于切换justify-content-end
类,它将导航项对齐到右侧而不是左侧。您可以切换以向任一方向滑动导航。 CSS过渡用于滑动动画。
演示:https://www.codeply.com/go/IHwAx16j14
<div class="container">
<div class="d-flex align-items-center">
<div class="flex-shrink-0">
<a href="#" class="btn-left btn-link toggle p-2"><i class="ion-chevron-left"></i></a>
</div>
<div class="flex-grow-1 w-100 o-hidden">
<ul class="nav nav-fill text-uppercase position-relative flex-nowrap">
<li class="nav-item">
<a href="#" class="nav-link">Home</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Self</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">World</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Lifestyle</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Bio</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Politics</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Local</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Science</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Tech</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Health</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Food</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Design</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Culture</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Travel</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">More</a>
</li>
</ul>
</div>
<div class="flex-shrink-0">
<a href="#" class="btn-right btn-link toggle p-2"><i class="ion-chevron-right"></i></a>
</div>
</div>
</div>
的jQuery
$('.toggle').click(function(){
$('.nav').toggleClass("justify-content-end");
});
CSS
.o-hidden {
overflow:hidden;
}
.nav {
transition: transform 0.4s;
transform: translateX(50%);
left: -50%;
}
.nav.justify-content-end {
transform: translateX(0);
left: 0;
}