reactjsfrontendreact-bootstrapweb-deployment-project

I'm unable to align my Navbar in react js


I'm quite new to ReactJS and I just started to make a portfolio web page. I started to make the navigation bar which would contain all the menus. Also, I made use of react-bootstrap.

I've already run the following commands on the terminal:

npm install --save react-bootstrap bootstrap
npm install --save bootstrap
npm install --save react-router-dom

Question 1:

How to get the desired navigation bar? It's not getting aligned to the right although I mentioned it to be 'ml-auto'. I doubt that it is because of the bootstrap issue.

import React from 'react';
import {BrowserRouter as Router, Route, Link } from 'react-router-dom';
import Container from 'react-bootstrap/Container';
import Navbar from 'react-bootstrap/Navbar';
import Nav from 'react-bootstrap/Nav';
import './App.css';

class App extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      title: 'Neha Chaudhary',
      headerLinks: [
        {title : 'Home', path : '/'},
        {title : 'Team', path : '/team'},
        {title : 'News', path : '/news'},
        {title : 'About', path : '/about'},
        {title : 'Reach Us', path : '/reachUs'},
        {title : 'Portfolio', path : '/portfolio'}
      ],
      home : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      },
      team : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      },
      news : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      },
      about : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      },
      reachUs : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      },
      portfolio : {
        title : "Becoming",
        subTitles : "Projects that make a difference",
        text : "Check out my projects below"
      }
    }
  }

  render() {
    return (
      <Router>
        <Container className="p-0" fluid={true}>

        <Navbar expand="lg" variant="light" bg="light">
            <Navbar.Brand>Neha</Navbar.Brand>

            <Navbar.Toggle className="border-0" aria-controls="navbar-toggle" />
            <Navbar.Collapse id="navbar-toggle">
              <Nav className="ml-auto">
                <Link className="nav-link" to="/">Home</Link>
                <Link className="nav-link" to="/portfolio">Portfolio</Link>
                <Link className="nav-link" to="/team">Team</Link>
                <Link className="nav-link" to="/news">News</Link>
                <Link className="nav-link" to="/about">About</Link>
                <Link className="nav-link" to="/reachUs">ReachUs</Link>

              </Nav>
            </Navbar.Collapse>
          </Navbar>

        </Container>
      </Router>
    );
  }
}

export default App;

Question 2:

Is the className="p-0" pre-defined? I was going through a video tutorial and it said it makes padding=0. So, if it pre-defined how can I get to know about all these classes?

Output

enter image description here


Solution

  • Did you include React-Bootstrap's CSS files?

    Check out the getting started documentation. There is a CSS file you need to include in order to get React-Bootstrap's styles.