Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap4 adding scrollbar to div

Tags:

bootstrap-4

I am using stacked pills inside a div. The problem is, sometimes the div contains a lot of pills. How can I add a scrollbar for it?

<div class="row col-md-2"> <ul class="nav nav-pills nav-stacked">   <li class="nav-item">     <a class="nav-link active" href="#">Active</a>   </li>   <li class="nav-item">     <a class="nav-link" href="#">Link</a>   </li>   <li class="nav-item">     <a class="nav-link" href="#">Link</a>   </li>   <li class="nav-item">     <a class="nav-link disabled" href="#">Disabled</a>   </li> </ul> </div> 

Can I add a class for the div to make stacked pills scrollable?

like image 571
FacundoGFlores Avatar asked Oct 18 '16 15:10

FacundoGFlores


People also ask

Can Div have scrollbar?

You need to add style="overflow-y:scroll;" to the div tag. (This will force a scrollbar on the vertical).

How do I add a scrollbar in bootstrap?

Add data-spy="scroll" to the element that should be used as the scrollable area (often this is the <body> element). Then add the data-target attribute with a value of the id or the class name of the navigation bar ( . navbar ). This is to make sure that the navbar is connected with the scrollable area.

How do you scroll a DIV in HTML?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.


1 Answers

Yes, It is possible, Just add a class like anyclass and give some CSS style. Live

.anyClass {   height:150px;   overflow-y: scroll; } 

.anyClass {    height:150px;    overflow-y: scroll;  }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/>    <div class=" col-md-2">    <ul class="nav nav-pills nav-stacked anyClass">      <li class="nav-item">        <a class="nav-link active" href="#">Active</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li><li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li><li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li><li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li><li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link" href="#">Link</a>      </li>      <li class="nav-item">        <a class="nav-link disabled" href="#">Disabled</a>      </li>    </ul>  </div>
like image 157
MD Ashik Avatar answered Oct 05 '22 08:10

MD Ashik