+ 1

Height px Vs %

When I assign div a height percentage It does not inherit it But when I give it in pixels it inherits Why https://code.sololearn.com/W7l3Jv2W0n3g/?ref=app

16th Apr 2020, 3:48 PM
Saad Saleem
Saad Saleem - avatar
3 odpowiedzi
+ 3
The % is a relative value to something. For example the div belongs to body, as in your code, then for the body will be needed an absolute value looks like follows: body { background:blue; height: 100vh; } div{ background:yellow; height: 50%; //height: 150px; }
16th Apr 2020, 4:13 PM
JaScript
JaScript - avatar
+ 2
Nice bro it's working
16th Apr 2020, 4:24 PM
Saad Saleem
Saad Saleem - avatar
+ 1
body{ background:blue; height : 100%; } div{ background:yellow; height:50%; // height : 150px; } First i try this use % instead of vh But i understand it now
16th Apr 2020, 4:25 PM
Saad Saleem
Saad Saleem - avatar