Recently, I've been attempting to implement CSS variables into a simple code but have encountered issues. Despite double-checking the information on how to properly use variables, I can't seem to pinpoint my mistake. Could it be that I am doing something incorrectly?
:root {
--my-color: red;
}
body {
background-color: var(--my-color);
}
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./style/mainPage.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="col-sm-12">
<h1>HELLO WORLD</h1>
</div>
</div>
</body>
</html>
I included the <head>
section in case any <link>
are causing compatibility issues with CSS variables.
In this code, the background-color remains white when using a variable, while it changes accordingly without a variable. Is there something crucial that I am overlooking?
Your help is greatly appreciated.