Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a DIV with vertical scrollable contents and fixed footer which is always visible?

Tags:

html

css

layout

The HTML should be sth like the following (sorry for the format and formatting but I do not know how to post HTML sample)

<div id="dialog-window">
  <div id="scrollable-content">
    what ever content here...div's, ul's and li's
  </div>
  <div id="footer">
  </div>
</div>

The result i'm looking for is to always have a vertical scrollbar only for the content and the footer should be always visible at the bottom of the dialog-window. The dialog-window is a fixed size dialog.

I have tried with some ideas from other posts here but do not fit all requirements. Any ideas to do this using CSS (js and jquery also welcome)

like image 215
Daniel Cerecedo Avatar asked Sep 21 '11 18:09

Daniel Cerecedo


People also ask

How do I keep my div visible when scrolling?

You need to put position: fixed; on the div element. That will anchor it to the viewport.

How do I make my div scrollable vertically?

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.

How do you get a div to stay at the bottom of the page?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.

How do I make a div scrollable vertically and horizontally?

We can use a combination of overflow-x and overflow-y to place the scrollbar vertically, horizontally, or both. For the vertical scrollbar, overflow-x:hidden and overflow-y:auto will be set in the CSS file, and vice versa for the horizontal scrollbar.


1 Answers

How about something like the below?

Just create a container which holds two divs one for the scrollable content and one for the footer. Fix all the heights and make the content div scrollable.

CSS (I won't charge for my expert color choices):

#dialog-window {
  height: 200px;
  border: 1px black solid;
}

#scrollable-content {
  height: 180px;
  overflow: auto;
  background-color: blue;
}

#footer {
  height: 20px;
  background-color: green;
}

Example of HTML

<div id="dialog-window">

  <div id="scrollable-content">
    <ul>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
      <li>Sample</li>
    </ul>
  </div>

  <div id="footer">
  </div>

</div>
like image 86
Paul.s Avatar answered Nov 02 '22 19:11

Paul.s