【发布时间】:2021-04-05 07:20:32
【问题描述】:
Once a square has been clicked, the color changes to red. - 这是使用活动类完成的
我希望 div 标签的背景颜色在单击正方形后保持不变。
代码
Board.js
{board.map((row, rowIdx) => (
<div key={rowIdx} className="row">
{row.map((cell, cellIdx) => (
<div key={cellIdx} className="cell"></div>
))}
</div>
))}
Board.css
.row {
height: 30px;
margin: 10px;
transition: transform 0.1s;
}
.cell:hover {
transform: scale(1.4);
}
.cell {
width: 30px;
height: 30px;
outline: 1px solid rgb(134, 154, 189);
display: inline-block;
background-color: seagreen;
margin: 5px;
transition: transform 0.2s;
}
.row :active {
background-color: red;
}
.cell :active { // Does not do anything
background-color: blue;
}
【问题讨论】:
-
尝试添加状态,检查 React 文档中的
style属性