2

How to add some custom CSS styles to the Nav component to manage the padding between the nav items and make it float right of the page?

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>
);
1
  • Do you want the navbar items to be displayed from right to left instead of left to right? Commented Mar 6, 2020 at 12:30

1 Answer 1

2

you would need to override the default CSS of bootstrap, you could check the class names using the inspector of your browser and modify those classes since the react-bootstrap compiles to bootstrap anyways

create a css file called Navbar.css

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

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

import it into navbar.js component

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>
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.