@media
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
* Some parts of this feature may have varying levels of support.
@media CSS @ê·ì¹ì ì¤íì¼ ìí¸ì ì¼ë¶ë¥¼ íë ì´ìì 미ëì´ ì¿¼ë¦¬ ê²°ê³¼ì ë°ë¼ ì ì©í ë ì¬ì©í ì ììµëë¤. @media를 ì¬ì©í´ 미ëì´ ì¿¼ë¦¬ë¥¼ ì§ì íë©´ í´ë¹ 쿼리를 ë§ì¡±íë ì¥ì¹ììë§ CSS ë¸ë¡ì ì ì©í ì ììµëë¤.
ì°¸ê³ :
JavaScriptììë @media를 CSSMediaRule CSS ê°ì²´ ëª¨ë¸ ì¸í°íì´ì¤ë¡ ì ê·¼í ì ììµëë¤.
구문
@media @ê·ì¹ì ìµìì ì½ëë, ì무 ì¡°ê±´ë¶ ê·¸ë£¹ @ê·ì¹ ìì ì¤ì²©í´ ìì±í ì ììµëë¤.
/* ìµìì ì½ë ë 벨 */
@media screen and (min-width: 900px) {
article {
padding: 1rem 3rem;
}
}
/* ë¤ë¥¸ ì¡°ê±´ë¶ @ê·ì¹ ë´ì ì¤ì²© */
@supports (display: flex) {
@media screen and (min-width: 900px) {
article {
display: flex;
}
}
}
미ëì´ ì¿¼ë¦¬ 구문ì ê´í ë´ì©ì 미ëì´ ì¿¼ë¦¬ ì¬ì©í기 문ì를 ì°¸ê³ íì¸ì.
ì ê·¼ì± ê³ ë ¤ì¬í
ê¸ì¨ í¬ê¸°ë¥¼ ì¡°ì í ì¬ì©ì를 ìí´ì, 미ëì´ ì¿¼ë¦¬ì <length> ì리ìë emì ì¬ì©íëê² ì¢ìµëë¤.
emê³¼ px 모ë ì í¨í ë¨ìì§ë§, ì¬ì©ìê° ë¸ë¼ì°ì ì ê¸ì¨ í¬ê¸°ë¥¼ ë³ê²½íë¤ë©´ emì´ ë ìì°ì¤ë½ê² ëìí©ëë¤.
Level 4 미ëì´ ì¿¼ë¦¬ë¥¼ íµí ì¬ì©ì ê²½í í¥ìë ê³ ë ¤í´ë³´ì¸ì. ì컨ë prefers-reduced-motion 쿼리를 ì¬ì©íë©´ ì¬ì©ìê° ìì¤í
ì ì ëë©ì´ì
ì ìµìë¡ ì¤ì¬ë¬ë¼ê³ ìì²íëì§ ì ì ììµëë¤.
ë³´ì
미ëì´ ì¿¼ë¦¬ë ì¬ì©ìì ì¥ì¹ì ë ëìê° ê¸°ë¥ê³¼ ëìì¸ì ëí íµì°°ì ì ê³µíë¯ë¡, "íê±°í린í "ì íµí´ ì¥ì¹ ê³ ì ìë³ìë¡ íì©íê±°ë, ê·¸ë³´ë¨ ë í´ë ì¬ì©ìê° ìíì§ ìì ìì¤ì ë¶ë¥ë¥¼ í기 ìí´ ì¤ì©í ê°ë¥ì±ì´ ììµëë¤.
ê·¸ë¬ë¯ë¡ ë¸ë¼ì°ì ë 기기ì í¹ì ì ë°©ì§í기 ìí´ ì¼ë¶ ë°í ê°ì 모í¸íê² í ì ììµëë¤. ëí ì¬ì©ììê² ì¶ê° ì¤ì ì ì ê³µí ìë ìëë°, ì를 ë¤ì´ Firefoxì "íê±°íë¦°í° ì°¨ë¨" 기ë¥ì íì±ííë©´ ë§ì ìì 미ëì´ ì¿¼ë¦¬ë ì¤ì ì¥ì¹ ìí ëì 기본 ê°ì ë³´ê³ íê² ë©ëë¤.
íì 구문
@media =
@media <media-query-list> { <rule-list> }
ìì
>ì¶ë ¥ê³¼ íë©´ 미ëì´ íì íë³
@media print {
body {
font-size: 10pt;
}
}
@media screen {
body {
font-size: 13px;
}
}
@media screen, print {
body {
line-height: 1.2;
}
}
@media only screen and (min-width: 320px) and (max-width: 480px) and (resolution: 150dpi) {
body {
line-height: 1.4;
}
}
Media Queries Level 4ë¶í°ë ìë¡ì´ ë²ì íí 구문ì ì¬ì©í´ ë ê°ê²°í 미ëì´ ì¿¼ë¦¬ë¥¼ ìì±í ì ììµëë¤.
@media (height > 600px) {
body {
line-height: 1.4;
}
}
@media (400px <= width <= 700px) {
body {
line-height: 1.4;
}
}
ë ë§ì ìì ë 미ëì´ ì¿¼ë¦¬ ì¬ì©í기를 ì°¸ê³ íì¸ì.
ëª ì¸
| Specification |
|---|
| Media Queries Level 4> # media-descriptor-table> |
| CSS Conditional Rules Module Level 3> # at-media> |
ë¸ë¼ì°ì í¸íì±
ê°ì´ 보기
- 미ëì´ ì¿¼ë¦¬ ì¬ì©í기
- JavaScriptìì
@mediaì ì ê·¼í ë ì¬ì©í ì ìë CSS ê°ì²´ ëª¨ë¸ ì¸í°íì´ì¤CSSMediaRule - Mozilla 미ëì´ í¹ì± íì¥
- WebKit 미ëì´ í¹ì± íì¥