One of the alternatives to not creating 3 equal classes is to create CSS classes that are applied only when used in conjunction with .card_head
. Each class of these will only take the background-color
.
.card_head {
padding: 25px;
background-color:#FE5959;
max-width: 30px;
max-height: 30px;
border-radius: 50%;
margin: 15px;
color: white;
font-family: 'Roboto', sans-serif;
display: flex;
justify-content: center;
align-items: center;
float: left;
}
.card_head.cor1 {
background-color: red;
}
.card_head.cor2 {
background-color: green;
}
.card_head.cor3 {
background-color: blue;
}
<div class="card_head cor1">Lorem</div>
<div class="card_head cor2">Lorem</div>
<div class="card_head cor3">Lorem</div>
Another way is to change the background through Javascript but I didn’t understand if this would be a solution for your scenario. Anyway follows an example:
function alterar() {
document.querySelector('div').style.backgroundColor = 'green';
}
.card_head {
padding: 25px;
background-color:#FE5959;
max-width: 30px;
max-height: 30px;
border-radius: 50%;
margin: 15px;
color: white;
font-family: 'Roboto', sans-serif;
display: flex;
justify-content: center;
align-items: center;
float: left;
}
<div class="card_head">Lorem</div>
<button onclick="alterar()">Alterar cor</button>
To do this you will need to use Javascript and change the class with different color for each one.
– Mauro Rocha
creates a class for the card and three classes for the background colors.
– user201467