I am trying to edit the CSS of my WordPress theme.
I have an element whose height I can successfully change from within Element Inspector, if I specify a certain pixel height, for example:
height=100px;
But when I try to change the height by specifying a percentage, for example:
height=50%;
The element does not change height. Any thoughts on what I’m doing wrong, or how to troubleshoot?
None of the parent elements appear to have any height properties.
Short Answer
Length values defined in percentage(%) gets value based on the value of containing box. Set the height of parent box to any absolute values (like height: 500px).
Long Answer
The default value of length properties(height,width) have default value
auto
, we should know how these values works(in block display):auto
:Width
is set in such a way that the block’s overall width(including border,padding,margin) occupies the parent block’s width.However,
Height
is always set according the calculated height of child elements (including border,padding,margin).`percentage(%): The length properties gets value according to that of the containing box.
The elements like body and div fill up the available width while having only the height required for the available content.
Before
After
http://jsfiddle.net/cMYdw/
The reason you are unable to change
height
% is because you need to set a100% height
on your parent element, in this case yourbody
.Now, it doesn’t necessarily have to be the
body
, it can be any parent element, but I’ve usedbody
in my example to get the idea across. For example, have a look below.