Right now I am dealing with a project that requires me to use responsive design instead of adaptive design(i.e. No media-quires; everything changes fluidly), and I am not sure which unit should I use for padding and margin.
For font-size, I am using rem
, which I believe is a good choice for responsive design, as I only needs to change the font-size
for html
to control their scale of change.
But for padding and margin, each unit comes with its drawback, at least in my opinion.
px
Hardcoding pixel is not an option here.
rem
To me, it does not make sense for padding and margin of containers to scale with font-size, but this is the easiest unit to use for responsive design.
vw
If I use vw, padding and margin of containers will scale with viewport width. This unit make sense to me, but I don't want to get the proportion of a unit relative to the viewport by writing calc( marginWidth/viewportWidth * 100vw)
everywhere. Is there a better way of writing and achieve the same result?
%
If I use %, padding and margin of containers will scale with parent's width. Again, I will have to do calc( marginWidth/viewportWidth * 100%)
. This is really cumbersome.
Is there a better way to set padding and margin for responsive css design? Would using CSS processor like tailwind css, postCSS or Sass help tackle this problem? Any opinion is welcomed.