Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making unordered list scrollable

I have an unordered list which is inside a div tag and initially the list is empty. When items are added on to it, it will expand and I want it to be scroll-able once it the length of the list exceeds that of the web page, i.e I do not want the web page to scroll, I want only the unordered list to scroll. However currently, the scroll bar for my unordered list is not appearing.

My html code is:

<div style="width: 25%; float: right; " class="online_users">
  <div class="panel panel-primary">
    <div class="panel-heading">
      <span class="glyphicon glyphicon-comment"></span> Online Users
        <ul id="ListOfOnlineUsers" style="overflow: auto;height:100%; word-wrap: break-word;" class="list-group">  
        </ul>
    </div>
  </div>
</div>

My CSS code is

html{
    height: 100%
}

{
  margin: 0;
  padding: 0;
}
body {
  padding: 50px;
  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
  height: 100%;

}

a {
  color: #00B7FF;
}

.chat
{
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat li
{
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px dotted #B3A9A9;
}

.chat li.left .chat-body
{
    /*margin-left: 60px;*/
}

.chat li.right .chat-body
{
    /*()margin-right: 60px;*/
}


.chat li .chat-body p
{
    margin: 0;
    color: #777777;
    word-wrap: break-word;
}

.panel .slidedown .glyphicon, .chat .glyphicon
{
    /*margin-right: 5px;*/
}

.panel-body
{
    overflow-y: scroll;
    top: 1em;
    left: 1em;
    height: 250px;
}

::-webkit-scrollbar-track
{
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    background-color: #F5F5F5;
}

::-webkit-scrollbar
{
    width: 12px;
    background-color: #F5F5F5;
}

::-webkit-scrollbar-thumb
{
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
    background-color: #555;
}


/* CSS used here will be applied after bootstrap.css */
body, html {
    height: 100%;
    background-repeat: no-repeat;
    background-image: linear-gradient(rgb(154, 145, 162), rgb(12, 97, 33));
}

.card-container.card {
    width: 350px;
    padding: 40px 40px;
}
.card {
    background-color: #F7F7F7;
    /* just in case there no content*/
    padding: 20px 25px 30px;
    margin: 0 auto 25px;
    margin-top: 50px;
    /* shadows and rounded borders */
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
}
.btn {
    font-weight: 700;
    height: 36px;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
    cursor: default;
}

.form-signin input[type=text],
.form-signin button {
    width: 100%;
    display: block;
    margin-bottom: 10px;
    z-index: 1;
    position: relative;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

.btn.btn-signin:hover,
.btn.btn-signin:active,
.btn.btn-signin:focus {
    background-color: rgb(12, 97, 33);
}
like image 840
user1692342 Avatar asked Apr 22 '15 09:04

user1692342


People also ask

How do you make a list scrollable in HTML?

CSS / HTML :min-height:200px;height:200px; max-height:auto; Here min-height is necessary to define. It tells that once the content exceed the 200px limit then show the scrollbar. max-height should be auto or 100%. I hope it will solve your problem.

How do I add a scroll to UL?

A: You can try to add the scroll bar for submenu manually. For this purpose you should open your page where you added the css3menu in any text editor and add class="scroll" into the <ul></ul> tag. You can also change the value of 'max-height' parameter.

How do you make a scrollable in CSS?

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

Set the list's max-height to the height of its parent (or whatever you need it to be) and then set its overflow property to auto.

Here's a quick example:

div{
  border:1px solid #000;
  font-family:arial;
  height:100px;
  width:200px;
}
ul{
  list-style:none;
  max-height:100px;
  margin:0;
  overflow:auto;
  padding:0;
  text-indent:10px;
}
li{
  line-height:25px;
}
li:nth-child(even){
  background:#ccc;
}
<div>
  <ul>
    <li>text</li>
    <li>text</li>
    <li>text</li>
    <li>text</li>
    <li>text</li>
    <li>text</li>
  </ul>
</div>
like image 147
Shaggy Avatar answered Sep 23 '22 22:09

Shaggy