I have a Bootstrap navigation menu with a flex container (). I want to enable horizontal scrolling for the menu items when they exceed the container width. I have applied the following CSS style to the container:
.nav {
display: flex;
flex-wrap: wrap;
overflow-x: auto;
width: 100%;
}
However, the horizontal scroll doesn’t seem to be working as expected. The menu items still wrap to the next line instead of providing a horizontal scroll.
Here is the HTML code for my navigation menu:
<ul class="nav nav-pills tab-listing" id="pills-tab" role="tablist">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4<li>
</ul>
2
Answers
Set
flex-wrap: nowrap
to prevent menu items from wrapping to the next line, and useoverflow-x:
auto to enable horizontal scrolling if the item exceeds the width of the container.Give a specific width to those you want to show the navigation menu on the entire screen, and then get horizontal scrolling as per your requirement.
Here you can change the value for the
max-width
as per your requirement to show menu on the screen and other is scroll.