CSS Layout Conundrum

I'm having to knock up a web page with a very specific layout.

Here's an example, complete with eye-gougingly ugly colours: (The container and Panel 2 work as they should do - it's Panel 1 that's wrong.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
body {
    background-color: gray;
}

#container {
    position: fixed;
    top: 20px;
    right: 20px;
    bottom: 20px;
    left: 20px;
    border: dashed red;
    overflow: hidden;
}

#panel1 {
    background-color: green;
    color: white;
    margin-bottom: 20px;
    padding: 20px;
    overflow: auto;
}

#panel2 {
    background-color: blue;
    color: white;
    padding: 20px;
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
}
</style>
</head>

<body>
    <div id="container">
        <div id="panel1">
            <h2>Panel 1</h2>
            <p>This panel should occupy all space in the container not occupied by Panel 2, with a scrollbar appearing when content overflows (ie overflow: auto) and a 20px bottom margin.</p>
        </div>
        <div id="panel2">
            <h2>Panel 2</h2>
            <p>This panel should be positioned at the bottom of the container and grow upwards depending on its content.</p>
        </div>
    </div>
</body>
</html>

Does anyone know the best way of achieving this? I rarely have to delve into CSS, so I could be missing something obvious. Ideally the solution should use CSS <= 2.1, be standards compliant, not reliant on JavaScript, and shouldn't rely on fixed heights.

Thanks!

Upvotes: 0

Views: 85

Answers (1)

m4tt1mus
m4tt1mus

Reputation: 1641

with your constraints, you can't.

Upvotes: 3

Related Questions