html - How to set the margin or padding as percentage of height of parent container? -


i had been racking brains on creating vertical alignment in css using following

.base{     background-color:green;     width:200px;     height:200px;     overflow:auto;     position:relative; }  .vert-align{     padding-top:50%;     height:50%; } 

and used following div structure.

<div class="base">    <div class="vert-align">        content here    </div> </div> 

while seemed work case, surprised when increased or decreased width of base div, vertical alignment snap. expecting when set padding-top property, take padding percentage of height of parent container, base in our case, above value of 50 percent calculated percentage of width. :(

is there way set padding and/or margin percentage of height, without resorting using javascript?

thanks in advance.

i had problem (+1). i'm annoyed it, stupid have this.

the fix yes, vertical padding , margin relative width, top , bottom aren't.

so place div inside another, , in inner div, use top:50% (remember position matters if still doesn't work)


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -