본문 바로가기
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>

'HTML_CSS' 카테고리의 다른 글

CSS 방법론 BEM 방식  (0) 2021.04.28
CSS - Animations 예제  (0) 2021.04.18
CSS - transition 예제  (0) 2021.04.17
CSS - Transitions Site  (0) 2021.04.03
CSS - 반응형 웹  (0) 2020.06.02