2

I'm trying to build a modular react application but have trouble with the navbar, for some reason the navbar is not formatting correctly.

WEbpage:-

enter image description here

Here is my complete code.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ReactStrap</title>
    <script src="https://unpkg.com/react@latest/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
    <script src="https://unpkg.com/[email protected]/babel.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
    var Navbar = React.createClass({
      render(){
        return(
          <nav className="navbar navbar-default">
            <div className="container">
              <div className="navbar-header">
                <a className="navbar-brand" href="#">ReactStrap</a>
              </div>
              <div id="navbar">
                <ul className="nav navbar-nav">
                  <li className="active"><a href="#">Home</a></li>
                  <li><a href="#">About</a></li>
                  <li><a href="#">Contact</a></li>
                </ul>
              </div>
            </div>
          </nav>
        );
      }
    });

    var Jumbotron = React.createClass({
      render(){
        return(
          <div>
          <div className="jumbotron">
            <div className="container">
              <h1>Hello, world!</h1>
              <p className="lead">This is a Bootstrap theme that uses React.js components</p>
              <p><a className="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
            </div>
          </div>
          </div>
        );
      }
    });

    var Page = React.createClass({
      render(){
        return(
          <div>
            <div className="container">
              This is the home page
            </div>
          </div>
        );
      }
    });
    var Theme = React.createClass({
      render(){
        return(
          <div>
            <Navbar />
            <Jumbotron />
            <Page />
          </div>
        );
      }
    });

    ReactDOM.render(
      <div>
        <Theme />
      </div>,
      document.getElementById('root'));
    </script>
  </body>
</html>
1
  • Did you checked the css for navbar? Commented Apr 22, 2017 at 22:10

1 Answer 1

1

bootstrap seem not to be included properly . here is a working jsbin

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ReactStrap</title>
    <script src="https://unpkg.com/react@latest/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
    <script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  </head>
  <body>
    <div id="root">react</div>

    <script type="text/babel">
    var Navbar = React.createClass({
      render(){
        return(
          <nav className="navbar navbar-default">
            <div className="container">
              <div className="navbar-header">
                <a className="navbar-brand" href="#">ReactStrap</a>
              </div>
              <div id="navbar">
                <ul className="nav navbar-nav">
                  <li className="active"><a href="#">Home</a></li>
                  <li><a href="#">About</a></li>
                  <li><a href="#">Contact</a></li>
                </ul>
              </div>
            </div>
          </nav>
        );
      }
    });

    var Jumbotron = React.createClass({
      render(){
        return(
          <div>
          <div className="jumbotron">
            <div className="container">
              <h1>Hello, world!</h1>
              <p className="lead">This is a Bootstrap theme that uses React.js components</p>
              <p><a className="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
            </div>
          </div>
          </div>
        );
      }
    });

    var Page = React.createClass({
      render(){
        return(
          <div>
            <div className="container">
              This is the home page
            </div>
          </div>
        );
      }
    });
    var Theme = React.createClass({
      render(){
        return(
          <div>
            <Navbar />
            <Jumbotron />
            <Page />
          </div>
        );
      }
    });

    ReactDOM.render(
      <div>
        <Theme />
      </div>,
      document.getElementById('root'));
    </script>
  </body>
</html>
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.