미디어 쿼리는 태블릿, 모바일, 데스크톱 등과 같은 다양한 장치에 스타일을 설정해야 할 때 사용됩니다.
다음 코드를 실행하여 미디어 쿼리로 반응형 탐색 메뉴를 만들 수 있습니다.
예
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<style>
.demo {
overflow: hidden;
background-color: blue;
}
.demo a {
float: left;
display: block;
color: white;
text-align: center;
padding: 10px;
text-decoration: none;
}
@media screen and (max-width: 600px) {
.demo a {
float: none;
width: 100%;
}
}
</style>
</head>
<body>
<p>Navigation Menu:</p>
<div class = "demo">
<a href = "#">Home</a>
<a href = "#">About</a>
<a href = "#">Tutorials</a>
<a href = "#">QA</a>
<a href = "#">Videos</a>
<a href = "#">Contact</a>
</div>
</body>
</html>