Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS의 변수

<시간/>

CSS의 변수는 웹 페이지에 사용자 정의 속성 값을 추가하는 데 사용됩니다. 속성의 사용자 정의 이름을 설정하고 값을 설정합니다.

배경 및 텍스트 색상을 변경하기 위해 CSS에서 변수를 구현하기 위해 다음 코드를 실행할 수 있습니다.

예시

<!DOCTYPE html>
<html>
   <head>
      <style>
         :root {
            --my-bg-color: blue;
            --my-color: white;
         }
         #demo {
            background-color: var(--my-bg-color);
            color: var(--my-color);
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <div id = "demo">This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text.
      </div>
      <br>
   </body>
</html>