Why use percentage value for div's width in CSS?

前端 未结 8 1855
无人及你
无人及你 2021-02-13 11:09

I am reading articles about css. I found out that many of writers suggest to use % value for div\'s width or height.

I am using pixels all the time.

Why should I

相关标签:
8条回答
  • 2021-02-13 11:51

    Because if it's percentage based content flows making it easier to implement a responsive site (easier = (less (time = money))).

    Drop the relevant floats, sort out your menus and and anything else after dropping in some media queries and you've got a site working on different resolutions and devices.

    I use a fluid grid system using percentages and a ems for text sizes. Pixels are easier to work with but not in responsive terms. I do wrap my size in max width container.

    PS

    Remember though everything boils down to pixels in the end.

    0 讨论(0)
  • 2021-02-13 11:51

    It's not clear which context you are referring to (what type of elements). However, you need to be careful when using pixels for font sizes.

    I generally use pixels for divs to keep my layout as expected. But I avoid pixels for fonts. Different users may want the font at different sizes. Why take that away.

    0 讨论(0)
提交回复
热议问题