As far as I know, when using css percentage for properties value for an relative element, this element checks the value of its parent and adjust the size based on this parent size.
What is the scenario for absolute elements?
I was looking through a css file and I found this:
html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow-x: hidden;
}
Is this ok to have percentage on absolute elements to get its browser width and height?
When an element has
position:absolute, thewidthandheightpercentages are calculated based on the whole browser dimensions.See below code:
Even though the width of parent div is only
200px, the element displays half of the browser width.Once I change it to
position:relative;, the alert will say100.