Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a horizontal-scrolling nav in Bootstrap?

As can be demonstrated in this fiddle, adding too many elements in a Bootstrap .nav causes it to just add items vertically down. How would I go about limiting its height and making it horizontally scrollable?

like image 502
Matoe Avatar asked Dec 09 '14 23:12

Matoe


People also ask

How do I make a horizontal scroll menu?

To create a horizontal menu first take a div container and add links to it then add CSS property to customize the menu like background-color , text-decoration , padding , margin etc. To add horizontal scroll use overflow: auto and white-space: nowrap .

Does scrollIntoView work horizontally?

((JavascriptExecutor) driver). executeScript("arguments[0]. scrollIntoView(true);", element); This works for vertical scrolling but not for horizontal.

How do I make a horizontal scrolling page?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.


1 Answers

First you need to tell the ul to not wrap and overflow into a scroll bar. Then the li elements need to not be floated and display inline. This will do it:

ul.nav {
    white-space: nowrap;
    overflow-x: auto;
}

ul.nav li {
    display: inline-block;
    float: none;
}

Fiddle: http://jsfiddle.net/bmfcd3zt/8/

like image 187
DavidG Avatar answered Sep 28 '22 06:09

DavidG