Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Help with Positioning Reply To: Help with Positioning

#238260
Paulie_D
Member

Let’s start at the beginning..

I want to set height of that element in % but unable to do so

% of what?

Percentage heights require that the heights of ALL ancestor elements be known or resolvable. That mean that all the way up the chain the height of each an every ancestor be either stated explicitly or can be calculated from a specific starting point.

The ultimate anscestor is the html element and it’s immediate child, the body…so if you want an element to be 50% of the page you need to set that first….usually at the same time.

html, body {
height: 100%;
}

Then I saw that you were trying to center the body…I’m not a fan of that.

In my opinion, it’s better to create a container with the set width (76% in your case) and center that with margin:auto. You can give that 100% height at the same time.

http://codepen.io/Paulie-D/pen/EPBLyN