user544079
user544079

Reputation: 16629

extend div height to entire webpage

Is there a way I can extend the height of a div to the entire webpage using css?

I am not using

.height
 {
  height:100%;
  }

But this will only extend to the height of the contents inside the div. The div should cover the entire webpage even if there is just a 1 line worth of content inside it.

Upvotes: 4

Views: 9731

Answers (5)

Edwin
Edwin

Reputation: 63

Make sure all parent items have a height set. html / body / etc.

The element will take 100% of it's parents height but only if the parent does HAVE a height.

100% Of a non set height will result in another non set height ;)

Upvotes: 5

alex
alex

Reputation: 490153

Use the min-height property.

.height {
   min-height: 100%;
}

But it is very dependent on context, of which you didn't provide.

Upvotes: 3

Richard JP Le Guen
Richard JP Le Guen

Reputation: 28753

You might have to specify a height for the <html> and <body> elements:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>extend div height to entire webpage</title>
    <style type="text/css">
        html, body {
            height:100%;
        }
        #tehDiv {
            height:100%;
            background:red;
        }
    </style>
</head>
<body>
    <div id="tehDiv">Example</div>
</body>
</html>

Upvotes: 0

ohmusama
ohmusama

Reputation: 4215

This worked for me:

<html>
    <head>
        <style type="text/css">
            body {
                margin: 0;
                padding: 0;
            }

            #wholepage {
                height: 100%;
                width: 100%;
                background: red;
                color: white;
                font-weight: 800;
                font-size: 22px;
                font-family: sans-serif;
            }
        </style>
    </head>
    <body>
        <div id="wholepage">
            Simple Test
        </div>
    </body>
</html>

Upvotes: 0

user319198
user319198

Reputation:

<div><!-- make a <div> to hold everything in.. -->

<div style="width:125;height:100%;">blah blah blah</div>

<div style="height:100%;">blah blah blah</div>

</div>

Upvotes: 1

Related Questions