react 行内设置button active
时间: 2023-09-11 19:04:13 浏览: 45
你可以使用 `style` 属性为按钮设置样式,其中包括 `backgroundColor` 和 `color` 等属性。具体地,为了设置按钮的 active 样式,你可以添加如下的样式:
```jsx
<button
style={{
backgroundColor: 'blue',
color: 'white',
boxShadow: 'none',
outline: 'none',
}}
>
Click me
</button>
```
其中,`boxShadow` 和 `outline` 属性用于去除默认的点击效果。你可以根据需要进行调整样式。
相关问题
react 设置button active
要设置React中按钮的活动状态,可以使用CSS伪类`:active`。当按钮处于活动状态时,该伪类将应用于按钮元素。
例如,您可以创建以下CSS规则来设置按钮的活动状态样式:
```
button:active {
background-color: #ccc;
color: #000;
}
```
这将在按钮被按下时将其背景颜色更改为灰色,并将文本颜色更改为黑色。然后,将此样式应用于您的按钮组件:
```
import React from 'react';
function MyButton() {
return (
<button className="my-button">Click me!</button>
);
}
```
然后,在CSS文件中,为`.my-button`类添加要应用的样式:
```
.my-button {
background-color: #fff;
color: #000;
border: none;
padding: 10px 20px;
}
.my-button:active {
background-color: #ccc;
color: #000;
}
```
这将使您的按钮在未被按下时具有白色背景和黑色文本,并在被按下时更改为灰色背景和黑色文本。
react 行内设置button点击后的背景颜色
你可以通过在 `style` 属性中设置 `backgroundColor` 来设置按钮在点击后的背景颜色,如下所示:
```jsx
<button style={{ backgroundColor: 'red' }} onClick={handleClick}>
Click me
</button>
```
这样,当按钮被点击时,它的背景颜色将变为红色。你可以将 `'red'` 替换为你想要的任何颜色值。