@Media anchura mínima y anchura máxima
Tengo esta configuración @media
:
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 */
}
Con esta configuración funciona en el iPhone, pero no funciona en el navegador.
¿Es porque ya tengo device
en el meta, y tal vez tengo max-width:480px
en su lugar?
3 answers
He encontrado que el mejor método es escribir su CSS predeterminado para los navegadores más antiguos, como los navegadores más antiguos, es decir, 5.5, 6, 7 y 8. No puedo leer @media. Cuando uso @media lo uso así:
<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>
Pero puedes hacer lo que quieras con tu @media, esto es solo un ejemplo de lo que he encontrado mejor para mí al crear estilos para todos los navegadores.
También! Si buscas imprimibilidad puedes usar @media print{}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-11 09:29:08
El problema subyacente es usar max-device-width
vs plain old max-width
.
El uso de la palabra clave "dispositivo" se dirige a la dimensión física de la pantalla, no al ancho de la ventana del navegador.
Por ejemplo:
@media only screen and (max-device-width: 480px) {
/* STYLES HERE for DEVICES with physical max-screen width of 480px */
}
Versus
@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. */
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-22 19:19:04
El valor correcto para el atributo content
debe incluir initial-scale
en su lugar:
<meta name="viewport" content="width=device-width, initial-scale=1">
^^^^^^^^^^^^^^^
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-12 00:28:34