将自定义css添加到React-Bootstrap组件

问题描述 投票:0回答:1

[如何向Nav组件中添加一些自定义CSS样式以管理导航项之间的填充并使之浮动在页面的右边?

const navbar = props => (
    <Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
    <Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
    <Navbar.Toggle aria-controls="responsive-navbar-nav" />
    <Navbar.Collapse id="responsive-navbar-nav">
      <Nav className="mr-auto">
        <Nav.Link href="#features">Home</Nav.Link>
        <Nav.Link href="#pricing">About Us</Nav.Link>
        <NavDropdown title="Facilities" id="collasible-nav-dropdown">
          <NavDropdown.Item href="#action/3.1">Library</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.2">Laboratories</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.3">Transportation</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.3">Hostel</NavDropdown.Item>
        </NavDropdown>
        <Nav.Link href="#pricing">Gallery</Nav.Link>
        <Nav.Link href="#pricing">Event</Nav.Link>
        <Nav.Link href="#pricing">Contact Us</Nav.Link>
      </Nav>
    </Navbar.Collapse>
  </Navbar>
);
css reactjs bootstrap-4 react-bootstrap react-component
1个回答
0
投票

您需要覆盖react-bootstrap的默认CSS,您可以使用浏览器的检查器检查类名,并修改这些类,因为react-bootstrap编译后仍会进行引导。

创建一个名为Navbar.css

 .navbar-nav {
  float: right !important;
}

.navbar-expand-lg .navbar-collapse {
  display: inline !important;
}

将其导入navbar.js组件

import "./Navbar.css";
    const navbar = props => (
    <Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
    <Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
    <Navbar.Toggle aria-controls="responsive-navbar-nav" />
    <Navbar.Collapse id="responsive-navbar-nav">
      <Nav className="mr-auto">
        <Nav.Link href="#features">Home</Nav.Link>
        <Nav.Link href="#pricing">About Us</Nav.Link>
        <NavDropdown title="Facilities" id="collasible-nav-dropdown">
          <NavDropdown.Item href="#action/3.1">Library</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.2">Laboratories</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.3">Transportation</NavDropdown.Item>
          <NavDropdown.Divider />
          <NavDropdown.Item href="#action/3.3">Hostel</NavDropdown.Item>
        </NavDropdown>
        <Nav.Link href="#pricing">Gallery</Nav.Link>
        <Nav.Link href="#pricing">Event</Nav.Link>
        <Nav.Link href="#pricing">Contact Us</Nav.Link>
      </Nav>
    </Navbar.Collapse>
  </Navbar>
);
© www.soinside.com 2019 - 2024. All rights reserved.