Responsive Layout - PX, EM, or %?

后端 未结 2 859
南方客
南方客 2020-12-15 20:32

I am building a responsive page layout and it works great so far, but I have a question:

Should I be using em, px or %?

For example, I want to have border r

相关标签:
2条回答
  • 2020-12-15 20:54

    Generally, don't use px for responsive layouts.

    If you use a px-based media query, then your layout may end up looking like crap when the user zooms. And unfortunately, that I know all to well because I made that mistake too.

    Regarding your example with border-radius, you may discover the two look really different when the font-size is increased - demo. The first and the third use px for border-radius, while the second and the fourth use em.

    But there will be exceptions and if something doesn't feel right on zoom (for example, a box-shadow that looks exaggerated), try it with px as well.

    Also check this article.

    0 讨论(0)
  • 2020-12-15 21:07

    Just for info, if it helps, it's possible to use rem . It solves the problem of "cascading size" with em. If you set

    body { font-size :62.5 %; } /* Trick to have 1em =10px */
    
    li {font-size:1.4em; }
    

    your <li> will be 14px, but if you have a list in a list, the second level <li> will be at 20px, and at third level will be 27px, etc.. With rem ( means "root em" ), all <li> are at the size you define.

    More info : http://snook.ca/archives/html_and_css/font-size-with-rem

    and http://www.pompage.net/traduction/dimensionner-ses-fontes-avec-rem ( in french )

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