2
I wanted to change the color of a table cell depending on the value entered by the user. For example A = green, B = blue, C = black, I managed to get the code to change the color of the table, but I’m not getting the user to change the color.
[data-color="1"],
[data-color="2"] {
background-color: gray;
}
[data-color="3"],
[data-color="4"] {
background-color: yellow;
}
[data-color="5"] {
background-color: red;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Trabalhando com seletores de atributos</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="color.css">
</head>
<body>
<table>
<thead>
<tr>
<th>Nome</th>
<th>Idade</th>
</tr>
</thead>
<tbody>
<tr data-color="1">
<td>Marco Bruno</td>
<td>1</td>
</tr>
<tr data-color="3">
<td>Antonio Silva</td>
<td>2</td>
</tr>
<tr data-color="3">
<td>Ricardo Souza</td>
<td>3</td>
</tr>
<tr data-color="4">
<td>Paulo Cesar</td>
<td>4</td>
</tr>
<tr data-color="5">
<td>Cesar Oliveira</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
Could you review your text and please use scores? It’s virtually impossible to understand what you did and what you want to do.
– Woss
Where the user will enter the value?
– Sam
in the field where age is
– Bruno Albuquerque
The ages will be A, B or C?
– Sam
not the age was only to exemplify the idea and by letters referring to the same color
– Bruno Albuquerque