CSS Layout How to - Stretch div to remaining size of screen








Question

We would like to know how to stretch div to remaining size of screen.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body, html {<!--from   ww  w. j  a v  a2  s  .  c  o m-->
  height: 100%;
  margin: 0;
  padding: 0;
}

header, footer {
  width: 100%;
  height: 100px;
  background: #EEE;
}

#content {
  position: absolute;
  top: 100px;
  bottom: 100px;
  width: 100%;
  background: #AAA;
}

nav {
  width: 20%;
  max-width: 250px;
  /*override*/
  width: 250px;
  height: 100%;
  float: left;
  background: #CCC;
}

#inside {
  height: 100%;
  overflow: auto;
}

footer {
  position: absolute;
  bottom: 0;
}
</style>
</head>
<body>
  <header>
    <h1>test layout</h1>
  </header>
  <div id="content">
    <nav>
      <ul>
        <li>link 1</li>
        <li>link 2</li>
        <li>link 3</li>
        <li>link 4</li>
        <li>link 5</li>
      </ul>
    </nav>
    <div id="inside">
      <h1>stretch the remaining size</h1>
      <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
        <br> Lorem <br/>ipsum <br/>dolor <br/>sit <br/>amet,
        
        repellat voluptas voluptates alias.</div>

    </div>
  </div>
  <!-- END CONTENT -->
  <footer>stuff</footer>
</body>
</html>

The code above is rendered as follows: