Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67556

Custom CSS property "background-color" not working

$
0
0

I've been trying to use CSS variables recently into a very simple code. It actualy did not work. I double checked the informations I found about how to use variables but I can't find my mistake. Maybe am I doing something wrong ?

: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 left the <head> in case of some <link> are not compatible with the utilisation of css variables.

With this code, the background-color stays white. If I do not use a variable instead, it changes accordingdy. Am I missing something ?

Thanks for your help.


Viewing all articles
Browse latest Browse all 67556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>