El uso de! Importante dentro del código contenido en sus consultas @media es una forma efectiva de agregar propiedades de estilo dinámico a los elementos de sus páginas, mientras deja intacto su CSS "predeterminado" para un fácil mantenimiento.
Ejemplo:
<html>
<head>
<style>
@media all and (max-width: 768px) {
/* CSS styles targeting screens of smaller sizes and/or resolutions (IE phones and tablets) */
#semantically-named-element p
{ width: 60% !important;
background: rgba(0,0,255,1)!important;
margin: auto !important; }
#semantically-named-element span
{ display: none !important; }
}
/* Look ma no media queries needed for default CSS below! Very easy to discern default styles, when the default code is the stuff not wrapped in queries. Period. */
/* Default CSS style attributes for any viewports that do not fit into the low or high resolution/screen size parameters set above and below. Also the fallback for browsers that still disregard CSS media queries */
#semantically-named-element p
{ width: 90%;
background: rgba(255,0,0,1);
margin: auto; }
#semantically-named-element span
{ display: block;
background: rgba(0,0,0,0.8);
color: #FFF;
text-align: center;}
@media all and (min-width: 968px) {
/* CSS styles targeting very large or very high resolution viewports at the 769 pixels wide "break-point" */
#semantically-named-element p
{ width: 80% !important;
background: rgba(0,255,0,1)!important;
margin: auto !important; }
#semantically-named-element span
{ display: block !important;
background: rgba(0,0,0,0.8)!important;
color: #FFF !important; font-size: 200%; }
}
</style>
</head>
<body>
<div id="semantically-named-element">
<p> Usage of !important inside of the code contained within your @media queries is an effective way to add dynamic style properties to your pages elements, while leaving your 'default' css intact for easy maintenance.<span>hidden until tablet greater 768 viewport pixel width</span></p>
</div>
</body>
</html>
Tu código funciona bien en mi sistema. He probado en Firefox, Chrome y Safari en Mac. ¿Cuál es tu entorno de prueba? – Anji
Perdón por la respuesta tardía. Estaba tratando de entender por qué no está funcionando. Aquí está: http://jsfiddle.net/TUL6h/3/ Intenta hacer el color azul cambiando el tamaño. Nunca sucede – jQuerybeast
Escogerá solo el color de cuál es el último en la sección de css. – jQuerybeast