CSS layout with fixed and fluid columns

I had a problem creating a layout that is partially fluid. The layout should have a width and height of 100%, but it should not have scrollbars (overflow: hidden;).

enter image description here

The image above shows what I'm trying to achieve. As you can see:

  • The title should be fixed - 110px with 100% width.
  • Two divs wrapped through a div container. Blue should be with a fixed width of 130px and 100% height, and green should be with a liquid width and a height of 100%.

Here is my current code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
    <style type="text/css">
        * {
            padding: 0;
            margin: 0px;
            color: white;
        }
        html, body {
            height: 100%;
            width: 100%;
        }

        .spacer {
            clear: both;
        }

        #header {
            background: black;
            width: 100%;
            height: 100px;
            float: left;
        }

        #content {
            height: 88%;
            width: 100%;
            padding: 0px;
            margin: 0px;
            position: relative;
        }

        #left {
            background: #1664a0;
            height: 100%;
            width: 100px;
            float: left;
        }

        #right {
            background: #4aa016;
            height: 100%;
            float: left;
            width: 91%;
        }

    </style>
</head>
<body>

<div id="header">
    My Header
</div>
<div class="spacer"></div>
<div id="content">
    <div id="left">Left container</div>
    <div id="right">Right container</div>
</div>

</body>
</html>

There are a couple of issues with this code:

  • It does not work with different resolutions (800x600, 1024x768, 1280x1024, etc.).
  • The "content" div does not always fill the page to the end.
  • If you resize the page to reduce resolution, the green div will be below cyan.

, - TERRIBLY , , -, " " ?

+3
2

http://jsfiddle.net/bmqPV/2/

100px 91%, , 100px 9%, .

EDIT, http://jsfiddle.net/bmqPV/4/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
    <style type="text/css">
        * {
            padding: 0;
            margin: 0px;
            color: white;
        }
        html, body {
            height: 100%;
            width: 100%;
        }

        .spacer {
            clear: both;
        }

        #header {
            background: black;
            width: 100%;
            height: 100px;
            position: absolute;
            top: 0px;
            left: 0px;
            z-index:3;
        }

        #content {
            height: 100%;
            width: 100%;
            padding: 0;
            margin: 0px;
            position: relative;
        }

        #left {
            background: #1664a0;
            height: 100%;
            width: 100px;
            float: left;
        }

        #right {
            background: #4aa016;
            height: 100%;
            width: 100%;
        }
        #wrapper
        {
            position: relative;
            height: 100%;
            width: 100%;}
        .contentcontainer {
            padding-top:100px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div id="header">
        My Header
    </div>
    <div id="content">
        <div id="left">
            <div class="contentcontainer">Left container</div>
        </div>
        <div id="right">
            <div class="contentcontainer">Right container</div>
        </div>
    </div>
</div>
</body>
</html>
+4

CSS #content #right , , . : -

    <!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
{
            padding: 0;
            margin: 0px;
            color: white;
        }
        html, body {
            height: 100%;
            width: 100%;
        }


        #header {
            background: black;
            height: 100px;
        }

        #content {
           width:100%;
           border:5px solid red;
           overflow:hidden;
           position:relative;

        }

        #left {
            background: #1664a0;
            height: 100%;
            width: 130px;
            float: left;
        }

        #right {
            background: #4aa016;
            height: 100%;
            float: left;
            width:100%;
            position:absolute;
            margin-left:130px;
        }

</style>
</head>
<body>
<div id="header">
    My Header
</div>

<div id="content">
    <div id="left">Left container</div>
    <div id="right">Right container</div>
</div>

</body>
</html>

see demo: - http://jsbin.com/ajasey/17/edit

0
source

All Articles