简体   繁体   English

如何更改子元素的按钮图标颜色

[英]How to change a button icon color of a child element

I have a Modal.Header with a closeButton (which is white by default) and I want to change its color to black.我有一个带有 closeButton(默认为白色)的 Modal.Header,我想将其颜色更改为黑色。

The code for the component is:该组件的代码是:

const inlineStyles = {
      header: {
        padding: '18px',
        margin: 0,
        backgroundColor: '#F2F3F4',
      },

<Modal.Header style={inlineStyles.header} closeButton >

The HTML of the rendered X-button looks like: <button type="button" aria-label="Close" class="close237497"></button>呈现的 X 按钮的 HTML 如下所示: <button type="button" aria-label="Close" class="close237497"></button>

我想让右边的带圆圈的 X 按钮“黑色”

Follow with this file of React-Bootstrap .跟随这个React-Bootstrap文件。 When you pass a closeButton prop into ModalHeader , the button will has class is close .当您将closeButton prop传递给ModalHeader ,该按钮的类将是close

So, you can override that class like this:因此,您可以像这样覆盖该类:

// create a file to override CSS bootstrap (override.css)
// override style of closeButton ModalHeader
.close {
   color: #fc0303 !important // red
   // orther style
}
import ModalHeader from 'react-bootstrap/ModalHeader';
import "./override.css";


// use ModalHeader
<ModalHeader closeButton />

使用Modal.Header的 style 道具在button设置样式,如下所示

<button type="button" aria-label="Close" style={this.props.style}></button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何给一个元素按钮添加一个激活的class,改变它的颜色和改变v-icon的颜色? - How to add an active class to an element button, change its color and change the v-icon color? 如何在 Vue 3 中单击按钮时更改图标的颜色? - How to change the color of an icon on button click in Vue 3? jQueryUI按钮:如何更改按钮图标的“颜色” - jQueryUI Button: How to change Button-Icon 'color' 如何访问子元素<h2>并更改背景颜色</h2> - How to access child element <h2> and change background color 如何在JavaScript中的Div子元素上更改文本颜色 - How to Change Text Color on a Div Child Element in JavaScript Bootstrap 和 JavaScript 按钮更改图标与背景颜色 - Bootstrap and JavaScript button change icon with background color 如何更改SVG图标的颜色? - How to change the color of an SVG icon? 如何更改 hover 上的图标颜色? - How to change icon color on hover? 包含应更改状态的图标的按钮元素 - A button element that contains an icon that should change state 为什么 CSS 'form' 元素的背景颜色不会针对整个表单发生变化,而不仅仅是它的子 'input' 和 'button' 元素? - why does CSS 'form' element background color not change for the whole form and not just its child 'input' and 'button' elements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM