user1323153
user1323153

Reputation: 37

Dynamic DIV height

In the HEAD of the page I have

<style type="text/css">
    html {
        overflow: hidden
    }
    html, body, #centralDIvision {
        margin-left: auto;
        margin-right: auto;
        width: 1100px;
        height: 400px;
    }
    #centralDivision {
        float: left;
    }
    #outer {
        display: table;
        position: absolute;
        height: 100%;
        width: 100%
    }
</style>

But instead of having the height of the centralDivision div equal to 400px, I'd like it to be 75% of the browser's current screen size. Is there a way for me to do this?

Upvotes: 0

Views: 442

Answers (3)

Eliran Malka
Eliran Malka

Reputation: 16263

just for diversity, another approach, using absolute positioning:

#parent {
    position: relative;
    height: 400px;
}
#child {
    position: absolute;
    top: 12.5%;
    bottom: 12.5%;
    left: 0;
    right: 0;
}​

and a working example on jsFiddle, of course.

Upvotes: 2

KatieK
KatieK

Reputation: 13853

#centralDIvision { height: 75%; } will get you pretty close, if the #centralDIvision element is a direct descendent of the body. (When height is specified in %, it's based on the parent's height.)

Upvotes: 1

JohnFx
JohnFx

Reputation: 34909

Have you tried replacing this

height: 400px;

with this?

height: 75%;

Upvotes: 0

Related Questions