如何在 Reactstrap 中更改背景颜色

How to change background colors in Reactstrap

我正在使用 React Strap 来帮助设置我正在创建的应用程序的样式,但是我不知道如何将导航的背景颜色从白色更改为黑色。我曾尝试在导航选项卡标签中为 ="dark" 上色,但这没有用。有帮助吗?

import React, { Component } from 'react';
import { Nav, NavItem, Dropdown, DropdownItem, DropdownToggle, DropdownMenu, NavLink } from 'reactstrap';

    export default class nav extends React.Component{

     constructor(props) {
        super(props);

        this.toggle = this.toggle.bind(this);
        this.state = {
          dropdownOpen: false
        };
      }

      toggle() {
        this.setState({
          dropdownOpen: !this.state.dropdownOpen
        });
      }

      render() {
        return (
          <div>
            <Nav tabs>
              <NavItem>
                <NavLink href="/" active>blank.</NavLink>
              </NavItem>
              <Dropdown nav isOpen={this.state.dropdownOpen} toggle={this.toggle}>
                <DropdownToggle nav caret>
                  Dropdown
                </DropdownToggle>
                <DropdownMenu>
                  <DropdownItem header>Header</DropdownItem>
                  <DropdownItem disabled>Action</DropdownItem>
                  <DropdownItem>Another Action</DropdownItem>
                  <DropdownItem divider />
                  <DropdownItem>Another Action</DropdownItem>
                </DropdownMenu>
              </Dropdown>
              <NavItem>
                <NavLink href="#">Link</NavLink>
              </NavItem>
              <NavItem>
                <NavLink href="#">Another Link</NavLink>
              </NavItem>
              <NavItem>
                <NavLink href="#">Disabled Link</NavLink>
              </NavItem>
            </Nav>
          </div>
        );
      }
    }

reactstrap 没有明确的文档,所以我在这里只看到 2 个选项:

  1. 只需在组件中使用内联样式

    <Nav style={{backgroundColor: '#f1f1f1'}}>Something</Nav>

  2. 或通过

    使用css-模块

    import styles from './Component.module.css' <Nav className={styles.Component}>Something</Nav> 在 css 中定义样式的位置 .Component{ background-color: #f1f1f1 }

注意:css-modules 有时不足以覆盖 bootstrap 样式,但内联样式应该有所帮助

实用程序 类 仍然可以使用 reactstrap。只需在父元素上使用 className='bg-dark',您就会得到深色背景。

一种使用样式组件的方法:

const MastHeadJumboTron = styled.div`
  &.jumbotron {
    background: #000;
  }
`;

const MastHead = () => (
  <Jumbotron as={MastHeadJumboTron} fluid>
    <Container>
      <h1>May the force be with you!</h1>
      <input placeholder="Filter People" />
    </Container>
  </Jumbotron>
);

根据文档,对于 AvField 作为输入,有像 inputClasslabelClass[=21 这样的道具=] 可帮助您分别管理文本框和标签的样式。

<AvField 
     name="member_name"
     label="Team Member Name"
     inputClass="bg-gradient-primary"
     type="text"
     placeholder="Name of Team Member"
     onChange={this.handleChange}
/>

对于 Input 组件,您可以使用 classNamecssModule 进行样式设置。

您可以用您的自定义 css 创建一个 class 并标记它们 !important。从而覆盖默认样式。

.custom-btn {
  background: #000 !important;
}