Since the color of the div
will change everyday anyway, I suggest you to set the color of the div
only in JavaScript instead of via CSS to prevent complication and undesired behaviour.
To set the color of an HTML element:
document.getElementById("your-div-id").style.background = color;
where color
is a string
, either a common color name ("blue", "black", "white" etc) or a hexadecimal string ("#FFF", "#123456", etc).
Don't forget to give your div
an id
first. (eg <div id="my-div"></div>
)
As I mentioned in the comment, it is possible to declare a hex number in JavaScript, but internally it will still be stored in decimal. It is not an issue though, but just take note when you are debugging.
To convert it to a hex string (taken from here):
var colorInHexString = colorInHexNumber.toString(16);
And because the HTML only accepts hex string with #
prepended, so don't forget to do that.
In case you do not know how to get the day of the month, you can get it from here.
tl;dr
So the full code:
<div id="my-div"></div>
<script>
var defaultColor = 0xC30000;
var multiplier = 0x20; // for example
var dayNumber = new Date().getDate() - 1; // first day of month uses defaultColor
var todayColor = defaultColor + dayNumber * multiplier;
var todayColorString = "#" + todayColor.toString(16);
document.getElementById("my-div").style.background = todayColorString;
</script>
Hope this helps.