Let's say there's a relatively positioned div element. When I set the top value in %, it does nothing at all. But as soon as I express it in px, it works. Is there any particular reason/logic?
This doesn't work
<style>
div{
position:relative;
height:300px;
width:300px;
top:20%;
}
</style>
<body>
<div>Hello</div>
</body>
While this works
<style>
div{
position:relative;
height:300px;
width:300px;
top:20px;
}
</style>
<body>
<div>Hello</div>
</body>
I tried putting this div inside a container and it worked. And the amount it moved was realtive to the height of the containing element.
For this to work, you need to set
heightto parent element, ormin-height+display: grid: