@ Media min-width & max-width

Mam taki @media setup:

HTML :

<head>
  <meta name="viewport" content="width=device-width, user-scalable=no" />
</head>

CSS:

@media screen and (min-width: 769px) {
    /* STYLES HERE */
}

@media screen and (min-device-width: 481px) and (max-device-width: 768px) { 
    /* STYLES HERE */
}

@media only screen and (max-device-width: 480px) {
    /* STYLES HERE */
}

Dzięki tej konfiguracji Działa na iPhonie, ale nie działa w przeglądarce.

Czy to dlatego, że mam już device w meta, a może zamiast tego mam max-width:480px?

Author: jacefarm, 2012-11-25

3 answers

Znalazłem najlepszą metodą jest napisanie domyślnego CSS dla starszych przeglądarek, jak starsze przeglądarki, w tym np. Nie mogę czytać @media. Kiedy używam @ media używam go w ten sposób:

<style type="text/css">
    /* default styles here for older browsers. 
       I tend to go for a 600px - 960px width max but using percentages
    */
    @media only screen and (min-width:960px){
        /* styles for browsers larger than 960px; */
    }
    @media only screen and (min-width:1440px){
        /* styles for browsers larger than 1440px; */
    }
    @media only screen and (min-width:2000px){
        /* for sumo sized (mac) screens */
    }
    @media only screen and (max-device-width:480px){
       /* styles for mobile browsers smaller than 480px; (iPhone) */
    }
    @media only screen and (device-width:768px){
       /* default iPad screens */
    }
    /* different techniques for iPad screening */
    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
      /* For portrait layouts only */
    }

    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
      /* For landscape layouts only */
    }
</style>

Ale możesz robić co chcesz ze swoimi mediami@, to tylko przykład tego, co znalazłem najlepsze dla mnie podczas budowania stylów dla wszystkich przeglądarek.

IPad CSS specyfikacji.

Również! Jeśli szukasz nadruku możesz użyć @media print{}
 268
Author: sourRaspberri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-11 09:29:08

Podstawowym problemem jest użycie max-device-width vs zwykły stary max-width.

Użycie słowa kluczowego "device" dotyczy fizycznego wymiaru ekranu, a nie szerokości okna przeglądarki.

Na przykład:

@media only screen and (max-device-width: 480px) {
    /* STYLES HERE for DEVICES with physical max-screen width of 480px */
}

Kontra

@media only screen and (max-width: 480px) {
    /* STYLES HERE for BROWSER WINDOWS with a max-width of 480px. 
       This will work on desktops when the window is narrowed.  */
}
 29
Author: jpostdesign,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-22 19:19:04

Poprawna wartość atrybutu content powinna zawierać initial-scale zamiast:

<meta name="viewport" content="width=device-width, initial-scale=1">
                                                   ^^^^^^^^^^^^^^^
 8
Author: Ksenia Titova,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-12 00:28:34