๐Ÿฆ_21.11.11 TIL

Boriยท2021๋…„ 11์›” 11์ผ
1
post-thumbnail

21๋…„ 11์›” 11์ผ

๐Ÿ“ CSS

๐Ÿ“Ž Media queries

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์˜ ์ตœ์†Œ, ์ตœ๋Œ€ ๋„ˆ๋น„
orientationviewport ๋ฐฉํ–ฅ

๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž

  • and : ์กฐ๊ฑด์„ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ์Šคํƒ€์ผ ์ ์šฉ
  • not : ์กฐ๊ฑด์„ ๋ฐ˜์ „ํ•˜๋Š” ๊ฒฝ์šฐ ์Šคํƒ€์ผ ์ ์šฉ
    • MDN ์„ค๋ช… : Used to negate a media query, returning true if the query would otherwise return false. If present in a comma-separated list of queries, it will only negate the specific query to which it is applied. If you use the not operator, you must also specify a media type.
  • only : ์ „์ฒด ์ฟผ๋ฆฌ๊ฐ€ ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ์Šคํƒ€์ผ ์ ์šฉ. ๋ฏธ๋””์–ด์ฟผ๋ฆฌ๋ฅผ ์ง€์›ํ•˜๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ์ž‘๋™
    • ๋ฏธ๋””์–ด ์ฟผ๋ฆฌCSS3 ๋ฒ„์ „์€ IE9๋ถ€ํ„ฐ ์ง€์›ํ•˜์ง€๋งŒ, ์‚ฌ์‹ค ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์ž์ฒด๋Š” ์ด๋ฏธ IE6๋ถ€ํ„ฐ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋• ์•„์ง ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์˜ค๋ฅ˜๋ฅผ ๋ฏธ์—ฐ์— ๋ฐฉ์ง€ํ•˜๊ณ ์ž 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?

๐Ÿ“Ž ์ฝ”๋“œ ๋ฆฌ๋ทฐ - ๋ฐ˜์‘ํ˜• ์›น ๊ตฌํ˜„

1๋งŒ ์‹œ๊ฐ„์˜ ๋ฒ•์น™


๋งˆ๋ฌด๋ฆฌ

  • ์–ด์ œํ–ˆ๋˜ ๊ณผ์ œ์— ๋Œ€ํ•ด ์ฝ”๋“œ ๋ฆฌ๋ทฐ๊ฐ€ ์ง„ํ–‰๋˜์—ˆ๋‹ค. ๋‹ค๋ฅธ ๊ต์œก์ƒ๋“ค์ด ์ž‘์„ฑํ•œ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋งŒ์œผ๋กœ ๋งŽ์€ ๊ฒƒ์„ ๋ฐฐ์› ๋‹ค!
    => ๋งˆํฌ์—… ์ž˜ํ•˜๊ณ  ์‹ถ๋‹ค์•„์•„
  • ์š” ๋ฉฐ์น  ์˜คํ›„์—๋Š” ์นดํŽ˜์— ๊ฐ€์„œ ์ˆ˜์—…์„ ๋“ค์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์‰ฌ๋Š” ์‹œ๊ฐ„์— ๋ƒ…๋‹ค ์—Ž๋“œ๋ ค์„œ ์ž ์„ ์ž๋Š”...
    => ์˜ค๋Š˜์€ ์ผ๋ถ€๋Ÿฌ ์•Œ๋žŒ ๋Šฆ๊ฒŒ ๋งž์ถฐ๋†จ๋Š”๋ฐ ์•Œ๋žŒ์ด ์šธ๋ฆฌ๊ธฐ ์ „์— ์ผ์–ด๋‚˜๋Š” ๊ฑด ์™œ ๋•Œ๋ฌธ์ด์ฃ ?

0๊ฐœ์˜ ๋Œ“๊ธ€