Viewport meta tags vs Media Queries?

前端 未结 4 1193
甜味超标
甜味超标 2020-12-04 15:45

I would love to know, to optimize your website for Tablets, desktops and smarthpones, what is best to use: Media Queries or the Viewport meta tags? see code:



        
4条回答
  •  误落风尘
    2020-12-04 16:28

    UPDATE: from 2020

    You'll want a viewport meta tag (always)

    https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag

    and almost always a few @media break-points

    but often (lately) - people try and leverage things with percentage, variable/relative units, flex-box, and auto-fill type grid situations to avoid @media queries

    I think that all of those things can just work together for the best results. I like @media queries for many reasons. : ) They are all just tools to use! Stick to the goals - and the right tools will present themselves.

    .....

    (original answer for back-story)

    i would say that every situation is different... and it is not an either / or situation. the viewport meta tag you have up there would make it so that the website will maintain the 1 to 1 ratio which in a lot of cases is good. however, it also is set user-scalable "no" - and that means that the user will not be able to zoom in etc... sometimes the way ipads and other devices change your site is for the best... (depends)

    the best method i have found is to use media queries and to choose one of 2 dirrections:

    1. start from small and build up
    2. start from large and build down

    stretch your browser window bigger and bigger (or smaller and smaller) and then when the website gets ugly, (just before) that is your next breakpoint... make the media query there... and repeat. don't pay attention to all of the device sizes --- this way you'll know that no matter what new devices etc come out --- you have engineered it to look nice at every possible size. (when it gets under 320 / i like to just make the site turn into a business card/// better to have readable info for none smart-phones...)

    then after all this... test on devices and try out different viewport meta tags.

    there are a lot of great articles about it... use keywords like "responsive design" or "adaptive" or "RWD" responsive web design. and good luck !!!

提交回复
热议问题