Media queries
@media ๋
ผ๋ฆฌ์ฐ์ฐ์ ๋ฏธ๋์ดํ์
๋
ผ๋ฆฌ์ฐ์ฐ์ (์กฐ๊ฑด) ๋
ผ๋ฆฌ์ฐ์ฐ์ {
์ ์ฉํ ์คํ์ผ
}
/* At the top level of your code */
@media screen and (min-width: 900px) {
article {
padding: 1rem 3rem;
}
}
/* Nested within another conditional at-rule */
@supports (display: flex) {
@media screen and (min-width: 900px) {
article {
display: flex;
}
}
}
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>๋ฏธ๋์ด์ฟผ๋ฆฌ ๊ธฐ๋ณธ</title>
<style>
/* mobile first!! bootstrap์ด ๋ํ์ */
body {
margin: 0;
background-color: tomato;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
box-sizing: border-box;
border: 10px solid red;
height: 500px;
width: 100%;
background-color: yellow;
}
.item {
margin: 50px;
width: 500px;
background-color: sienna;
}
/* max๋ 1000px ์ด์์ด๋ผ๊ณ ์คํดํ๊ธฐ ์ฝ์ง๋ง, 1000px ์ดํ์ผ๋ ์๋, ๊ทธ๋ฌ๋ 1000px์ผ๋๊น์ง!๋ผ๊ณ ์ดํดํ๋ ๊ฒ์ด ์ข์ */
@media screen and (max-width:1000px) {
body {
background-color: green;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
box-sizing: border-box;
border: 10px solid red;
height: 800px;
width: 100%;
background-color: yellow;
}
.item {
margin: 50px;
width: 800px;
background-color: sienna;
}
}
@media screen and (max-width:500px) {
body {
background-color: violet;
}
}
</style>
</head>
<body>
<div class="container">
<div class="item">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsam ea illo eius architecto sed qui, incidunt corporis labore! Nobis nemo consequuntur commodi pariatur iure saepe dolorum neque tempore temporibus at!</div>
<div class="item">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsam ea illo eius architecto sed qui, incidunt corporis labore! Nobis nemo consequuntur commodi pariatur iure saepe dolorum neque tempore temporibus at!</div>
</div>
</body>
</html>
all
: ๋ชจ๋ ์ฅ์นprint
: ์ธ์ ๊ฒฐ๊ณผ๋ฌผ ๋๋ ์ธ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํ๋ฉด์ ํ์ํ๋ ๊ฒฝ์ฐ<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="reset.css" />
<style>
@media print {
abbr::after {
/* attr() : css ์์ฑ ํจ์์
๋๋ค. */
content: " (" attr(title) ")";
}
}
</style>
</head>
<body>
<abbr title="world wide web consortium">w3c</abbr>
</body>
</html>
screen
: ๋ชจ๋ํฐ๋ ์คํฌ๋ฆฐ์ด ์๋ ๋๋ฐ์ด์ค ์๋ฏธspeech
: ์์ฑ ์ถ๋ ฅ ์ฅ์น(speech synthesizer)webkit-min-device-pixel-ratio webkit-min-device-pixel-ratio | ์ถ๋ ฅ ์ฅ์น์ ์ต์, ์ต๋ ํฝ์
๋น์จ. CSS์ 1px ์์ ๋ค์ด๊ฐ๋ ์ฅ์น์ ์คํฌ๋ฆฐ ํ์ ์ ์ซ์๋ฅผ ๊ฐ์ผ๋ก ํ๋ค. |
min-width / max-width | ์คํฌ๋กค ๋ฐ๋ฅผ ํฌํจํ viewport ์ ์ต์, ์ต๋ ๋๋น |
orientation | viewport ๋ฐฉํฅ |
and
: ์กฐ๊ฑด์ ๋ชจ๋ ๋ง์กฑํ๋ ๊ฒฝ์ฐ์๋ง ์คํ์ผ ์ ์ฉnot
: ์กฐ๊ฑด์ ๋ฐ์ ํ๋ ๊ฒฝ์ฐ ์คํ์ผ ์ ์ฉ only
: ์ ์ฒด ์ฟผ๋ฆฌ๊ฐ ์ผ์นํ๋ ๊ฒฝ์ฐ์๋ง ์คํ์ผ ์ ์ฉ. ๋ฏธ๋์ด์ฟผ๋ฆฌ๋ฅผ ์ง์ํ๋ ๋ธ๋ผ์ฐ์ ์์๋ง ์๋only
ํค์๋๊ฐ ํ์ํ๊ฒ ๋์๋ค. ,
(comma) : ์ฌ๋ฌ ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ฅผ ์ ์ฉํ ๋ ์ฌ์ฉ. ์กฐ๊ฑด ์ค ํ๋๋๋ก ๋ง์กฑํ๋ ๊ฒฝ์ฐ ์คํ์ผ ์ ์ฉbody{background:black;}
@media screen and (min-width:481px) and (max-width:1280px){
body{background:red;}
}
@media screen and (max-width:480px){
body{background:green;}
}
@media not screen and (orientation : landscape){ /* not์ ํญ์ @media ๋ค์ ์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ portrait */
body{background:pink;}
}
@media screen and (-webkit-device-pixel-ratio : 2){
body{background:royalblue;}
}
- ๊ธฐ๊ธฐ์ ํฝ์ ๋น์จ์ ์ ์ ์๋ ๋ฐฉ๋ฒ
- BOM API ์ด์ฉ
๊ฐ๋ฐ์ ๋๊ตฌ > ์ฝ์์ฐฝ์ "window.devicePixelRatio" ์ ๋ ฅ
๋ธ๋ผ์ฐ์ ํ๋/์ถ์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ฏ๋ก ์ฃผ์- What's My Device Pixel Ratio?