Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make this 100% height + column overflow layout work in Firefox and IE?

Tags:

html

css

I have a three-column layout that takes up 100% width and height of the browser (with padding). This layout contains two columns which also take up 100% height and should scroll independently.

Here is a jsfiddle: http://jsfiddle.net/KdZ9A/2/. Here is how it looks in Chrome (desirable -- individual columns scroll):

enter image description here

and Firefox and IE (undesirable -- body is scrolling):

enter image description here

This works perfectly in Chrome; however, the in Firefox and IE (10), the entire page scrolls instead of individual columns scrolling. I only want the columns to overflow and scroll -- not the body. Any idea how to make this work in Firefox and IE?

I've also tried a bit different approach using absolute positioning of the columns' contents: http://jsfiddle.net/KdZ9A/3/.

Here is the HTML I am using:

<div id="container">
    <div id="inner">
        <div id="palette">palette</div>
        <div id="list">
            <div class="content"></div>
        </div>
        <div id="editor">
            <div class="content"></div>
        </div>
    </div>
</div>

I'm using absolute positioning to achieve 100% height and then display of table and table-cell inside that to achieve 100% height of the columnns:

* {
    padding: 0;
    margin: 0;
}

html, body {
    width: 100%;
    height: 100%;
}

body {
    position: relative;
}

#container {
    background-color: #f1f1f1;
    position: absolute;
    left: 20px;
    right: 20px;
    top: 20px;
    bottom: 20px;
}

#inner {
    display: table;
    height: 100%;
}

#inner > div {
    display: table-cell;
}

#palette {
    min-width: 180px;
    max-width: 180px;
    width: 180px !important;
    background-color: pink;
}

#list {
    width: 55%;
    min-width: 350px;
    background-color: cyan;
}

#editor {
    width: 45%;
    min-width: 400px;
    background-color: magenta;
}

.content {
    overflow: auto;
    height: 100%;
}
like image 829
Chad Johnson Avatar asked Jun 01 '14 19:06

Chad Johnson


People also ask

Which property can be used to set an element to show a scroll bar when the text overflows?

The overflow property specifies what should happen if content overflows an element's box. This property specifies whether to clip content or to add scrollbars when an element's content is too big to fit in a specified area.

What is overflow clip CSS?

The overflow-clip-margin CSS property determines how far outside its bounds an element with overflow: clip may be painted before being clipped.

What is overflow hidden CSS?

overflow:hidden prevents scrollbars from showing up, even when they're necessary. Explanation of your CSS: margin: 0 auto horizontally aligns the element at the center. overflow:hidden prevents scrollbars from appearing.


2 Answers

I was 5 minutes from giving up and HOLY CRAP...I GOT IT WORKING

http://jsfiddle.net/gFX5E/15/

This is based on the different approach I mentioned. I needed to wrap .content divs and make the wrappers position relative. I also added some headers to the columns.

HTML:

<div class="content-wrap">
    <div class="content">
        ...
    </div>
</div>

CSS:

.content-wrap {
    position: relative;
    height: 100%;
}

.content {
    overflow: auto;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
}

Seems to work in Chrome, Safari, Firefox, and IE8+.

And here is a more semantic HTML5 version which also adds a header to the top: http://jsfiddle.net/gFX5E/20/. I believe this will require use of html5shiv to work in IE8.

like image 198
Chad Johnson Avatar answered Oct 01 '22 18:10

Chad Johnson


If you are willing to settle for a fixed total width, here is how:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box; /* makes filling up easier */
    }
    html, body {
      height: 100%;
    }
    #container {
      position: relative;
      width: 980px;
      height: 100%;
      margin: auto;
      background: grey;
    }
    #palette {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 800px;
      background: pink;
    }
    #list {
      position: absolute;
      left: 180px;
      top: 0;
      bottom: 0;
      right: 450px;
      background: cyan;
      overflow-y: auto;
    }
    #editor {
      position: absolute;
      left: 530px;
      top: 0;
      bottom: 0;
      right: 0;
      background: magenta;
      overflow-y: auto;
    }
</style>
</head>
<body>
  <div id="container">
    <div id="palette">Palette</div>
    <div id="list" class="content"></div>
    <div id="editor" class="content"></div>
  </div>
<script>
    $(function() {
        for (var i=0; i<20; i++) {
            $('.content').append('<p>Lorem ipsum [truncated for SO]</p>');
        }
    });
</script>
</body>
</html>

Demo on this Codepen: http://codepen.io/anon/pen/aqgCm?editors=100.

like image 25
Frank Conijn Avatar answered Oct 01 '22 17:10

Frank Conijn