Please in what scenario should i make use of vh,vw rather than percentage or px in css.
width:100%;height:100%;
or
width:100vw;height:100vh;
Which is advisable and why?
Please in what scenario should i make use of vh,vw rather than percentage or px in css.
width:100%;height:100%;
or
width:100vw;height:100vh;
Which is advisable and why?
The benefit of being able to use a viewport relative unit is probably in something like font size. When using vws or vhs, units are relative to the viewport rather than relative to their parent or the root as in other CSS units.
So if you wanted to make your font size 10% of the viewport width without calculating it in ems, rems, or pixels, you can simply declare font-size:10vw.
vw and percent are not the same since percentages are relative to the parent container. If you have a div set to width:50% inside a container set at 1200px on a window that is 1400px wide, your div will be 600px wide (1200 * 50%). Using vws, however, your width will be 50% of the viewport size, therefore 700px (1400px *50%). I made this codepen to illustrate the difference.
Hope that helps!