티스토리 뷰

CSS

[HTML/CSS] Custom Properties

baegofda_ 2020. 8. 6. 11:11

* Custom Properties

  • 색상이나 사이즈 등을 변수로 정의하여 사용한다.
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Custom properties</title>
    <!-- https://developer.mozilla.org/en-US/docs/Web/CSS/--* -->
    <style>
      :root {
        --background-color: thistle;
        --text-color: whitesmoke;
        --base: 8px;
      }
      .first-list {
        background-color: var(--background-color);
        color: var(--text-color, red);
        margin-left: var(--base);
      }

      .second-list {
        background-color: var(--background-color);
        color: var(--text-color, red);
        margin-left: calc(var(--base) * 2);
      }

      @media screen and (max-width: 768px) {
        :root {
          --background-color: salmon;
          --text-color: whitesmoke;
          --base: 4px;
        }
      }
    </style>
  </head>
  <body>
    <ul class="first-list">
      <li>Orange</li>
      <li>Apple</li>
    </ul>
    <ul class="second-list">
      <li>Korea</li>
      <li>Japan</li>
      <li>China</li>
    </ul>
  </body>
</html>

'CSS' 카테고리의 다른 글

🎁 CSS에서의 Box Model ?  (0) 2020.11.04
💡 CSS 란 무엇일까?  (0) 2020.11.04
[HTML/CSS] Transition  (0) 2020.08.02
[HTML/CSS] background  (0) 2020.08.02
[HTML/CSS] box, text 정렬하기 ( margin, text-align, translate, text centering)  (0) 2020.08.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함