React Bootstrap,为NavItems添加悬停效果

时间:2017-10-17 15:15:01

标签: css twitter-bootstrap reactjs react-bootstrap

React Bootstrap全新,我一直在尝试为组件添加一些自定义样式。

我可以通过使用chrome检查器找到类名来从Nav中删除边界半径,但我还没有能够为我的NavItems添加悬停效果。

这是我的组件。

 <Navbar inverse collapseOnSelect className="nav-bar">
    <Navbar.Header>
      <Navbar.Brand>
        <a href="#">efrt</a>
      </Navbar.Brand>
      <Navbar.Toggle />
    </Navbar.Header>
    <Navbar.Collapse>
      <Nav>
        <NavItem eventKey={1} href="#">Features</NavItem>
        <NavItem eventKey={2} href="#">Who we Are</NavItem>
      </Nav>
      <Navbar.Form pullRight>
        <UniversalButton style="primary" name='Login' />
      </Navbar.Form>
      <Nav pullRight>
        <NavDropdown eventKey={3} title="Signup" id="basic-nav-dropdown">
          <MenuItem eventKey={3.3}>Member</MenuItem>
          <MenuItem divider />
          <MenuItem eventKey={3.3}>Coach</MenuItem>
        </NavDropdown>
      </Nav>
    </Navbar.Collapse>
  </Navbar>

从Chrome检查器复制,我得到以下内容作为我想要进行更改的类/元素

.navbar-inverse .navbar-nav>li>a {
    color: #9d9d9d;
} 

当我尝试以下时,没有任何反应。我尝试添加自定义类名也没有效果。

.navbar-inverse.navbar-nav>li>a:hover {
    background: grey;
} 

任何帮助表示感谢:)!

1 个答案:

答案 0 :(得分:3)

.navbar-inverse .navbar-nav之后您遗漏了一个空格,因为.navbar-inverse .navbar-nav > li > a:hover { background-color: gray; } 是孩子:

const { Navbar, Nav, NavItem, NavDropdown, MenuItem } = ReactBootstrap;

class App extends React.Component {
  render() {
    return (
      <div>
        <Navbar inverse collapseOnSelect className="nav-bar">
          <Navbar.Header>
            <Navbar.Brand>
              <a href="#">efrt</a>
            </Navbar.Brand>
            <Navbar.Toggle />
          </Navbar.Header>
          <Navbar.Collapse>
            <Nav>
              <NavItem eventKey={1} href="#">
                Features
              </NavItem>
              <NavItem eventKey={2} href="#">
                Who we Are
              </NavItem>
            </Nav>
            <Navbar.Form pullRight />
            <Nav pullRight>
              <NavDropdown eventKey={3} title="Signup" id="basic-nav-dropdown">
                <MenuItem eventKey={3.3}>Member</MenuItem>
                <MenuItem divider />
                <MenuItem eventKey={3.3}>Coach</MenuItem>
              </NavDropdown>
            </Nav>
          </Navbar.Collapse>
        </Navbar>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));

运行示例:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.31.3/react-bootstrap.min.js"></script>
<style>
  .navbar-inverse .navbar-nav>li>a:hover {
    background-color: green;
  }
</style>
<div id="root"></div>
while True:
    start = input("Enter Roll or Quit? ")
    # [more code]