HTML_CSS
CSS - Media Query 예제
by le_piee
2021. 4. 18.
<!DOCTYPE html>
<html lang="kr">
<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>
<style>
body {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
flex-direction: column;
}
div {
background-color: teal;
width: 200px;
height: 200px;
}
span {
font-size: 36px;
}
/*화면이 400px보다 작으면 이걸 적용*/
@media screen and (max-width: 400px) {
div {
background-color: orange;
}
}
/*화면이 400px보다 크고 750px보다 작을경우 이걸 적용*/
@media screen and (min-width: 400px) and (max-width: 750px) {
div {
background-color: blue;
}
}
/*가로모드*/
@media screen and (orientation: landscape) {
span {
display: none;
}
}
</style>
</head>
<body>
<div></div>
<span>핸드폰을 가로모드로 돌려주세요</span>
</body>
</html>