Can i overlap two background-colors?
I’m coding div tags for two team, one is teamA the other is teamB.
Each div is for each member.
document.getElementsByClassName('teamA').style.backgroundColor = "rgba(0, 0, 255, 0.3)";
document.getElementsByClassName('teamB').style.backgroundColor = "rgba(255, 0, 0, 0.3)";
The result i want is, a div class(user) in which both ‘teamA’ and ‘teamB’ belong, is a mixture of two colors(mixture of teamA and teamB color).
How can i do with javascript?
2
Answers
One approach is below, though this answer may need revising should you update the question. At this point, though, I feel it answers your question; explanatory comments are in the code to explain what’s happening and there are references at the end to aid in further research.
Please note that one method I use in this answer is to use the
color-mix()
function which is – at the time of writing – a very new feature, you may wish to look at the compatibility table for that function (it’s on the reference linked in the references, below) and it may not work, or it may appear to do nothing in your current browser (use the developer tools to inspect the element if so):JS Fiddle demo.
References:
background-color
.block-size
.box-shadow
.box-sizing
.clamp()
.color-mix()
.display
.flex
.flex-direction
.font-family
.gap()
.grid-column
.grid-template-columns
.inline-size
.justify-content
.linear-gradient()
.margin
.margin-inline
.padding
.padding-block
.padding-inline
.place-contents
.repeat()
.text-align
.