Media Queries
📝 O que são Media Queries?
Media Queries são regras CSS que permitem aplicar estilos diferentes baseados em características do dispositivo, como largura da tela, orientação e resolução.
@media (min-width: 768px) {
.container {
max-width: 1200px;
}
}
📊 Sintaxe Básica
@media (condição) {
/* estilos aqui */
}
🎯 Tipos de Media Features
- width/min-width/max-width: Largura da viewport
- height/min-height/max-height: Altura da viewport
- orientation: portrait ou landscape
- resolution: Resolução do dispositivo
- aspect-ratio: Proporção da tela
Exemplos Comuns
/* Mobile */
@media (max-width: 767px) { }
/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) { }
/* Desktop */
@media (min-width: 1024px) { }
/* Orientação */
@media (orientation: landscape) { }
🔧 Breakpoints Comuns
- Mobile: até 767px
- Tablet: 768px - 1023px
- Desktop: 1024px+
- Large Desktop: 1440px+
💡 Dica: Use min-width (Mobile First)
Comece com estilos mobile e use min-width para adicionar estilos para telas maiores:
/* Base (mobile) */
.container { width: 100%; }
/* Tablet e acima */
@media (min-width: 768px) {
.container { max-width: 750px; }
}
/* Desktop e acima */
@media (min-width: 1024px) {
.container { max-width: 1200px; }
}