Day 27: Css Variable

 :root {

  --main-color: #3498db;

}


.element {

  background-color: var(--main-color);

}



HTML Code:

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="stylesheet" href="styles.css">

  <title>Sample Page</title>

</head>

<body>

  <div class="element">

    This is a sample element with the specified background color.

  </div>

</body>

</html>


CSS Code:

:root {
  --main-color: #3498db;
}

.element {
  background-color: var(--main-color);
  padding: 20px;
  color: white; /* Text color to make it visible on the background */
}




Comments

Popular posts from this blog

Day 9: CSS - Font Formate

else-if condition in if-else statements: Concatenation in JavaScript :