What unit or approach is best (or at least good!) practice for using measurements relative to screen size? I'm constraining this question to mobile devices, which I suspect may affect the answers. I'd thus wrap the styles inside @media (hover:none), (hover:on-demand) { }.
Asked
Active
Viewed 180 times
1 Answers
5
[...] measurements relative to screen size
For elements at the top level within <body> you can use %.
But in many cases I'd be inclined to use viewport units:
vw- 1% of the viewport widthvh- 1% of the viewport heightvmax- equal to 1% of whichever is larger, viewport width or viewport heightvmin- equal to 1% of whichever is smaller, viewport width or viewport height
Further Reading:
Rounin
- 2,335
- 2
- 16
- 33
vwis that if there's a scrollbar then the box will ignore it, leaving horizontal and vertical scrolling. Butvhalways works fine. – corn on the cob Aug 25 '20 at 15:18100vwand100%of<body>give different results depending on what type of scrollbar you're dealing with - a touchscreen style scrollbar or a desktop window viewport style scrollbar. This is consistently a pain, but it won't be resolved until we have OS-agnostic scrollbars. – Rounin Aug 25 '20 at 18:01