skip to Main Content

I have built a simple webpage using Twitter Bootstrap, and I have 2 problems:

  1. Although I have given the navbar a class of navbar-inverse, it just appears as a white rectangle and looks no different to the rest of the webpage. Divs with a class of navbar-inverse are supposed to have inverse colours: a dark background-color, and light text.
  2. I have three links with an empty href, but they don’t appear. They still don’t appear if I give them a href of #.

Here is a link to the result I am getting: http://jsbin.com/poqofapiqa/edit?html,output

2

Answers


  1. Navbars:

    Use the navbar-dark and bg-dark classes instead:
    <nav class="navbar navbar-dark bg-dark"><!-- Navbar content --></nav>

    Links:

    Use at least <a href="#">...</a> , not blank href attribute.
    Anchors with blank attributes interpreted as usual (non-link) elements

    <!doctype html>
    <html lang="en">
      <head>
        <title>Hello, world!</title>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    	
    	<style>
    	
    		.box {
    			border:1px solid grey;
    			background-color:#d3d3d3;
    		}
    	
    	</style>
    	
      </head>
      <body>
      
    	<div class="navbar navbar-dark bg-dark">
    		
    		<div class="container">
    			
    			<div class="navbar-header">
    				
    				<a href="#" class="navbar-brand">My Website</a>
    				
    			</div>
    			
    			<div class="collapse navbar-collapse">
    				
    				<ul class="nav navbar-nav">
    					
    					<li><a href="#">Page 1</a></li>
    					
    					<li><a href="#">Page 2</a></li>
    					
    					<li><a href="#">Page 3</a></li>
    					
    				</ul>
    				
    			</div>
    			
    		</div>
    		
    	</div>
    	
        <h1>Hello, world!</h1>
    	
    	<div class="container">
    		
    		<div class="row">
    		
    			<div class="col-md-4 box">Content</div>
    			
    			<div class="col-md-4 box">Content</div>
    			
    			<div class="col-md-4 box">Content</div>
    			
    		</div>
    		
    	</div>	
    	
        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
      </body>
    </html>
    Login or Signup to reply.
  2. You are using it in a wrong way. Class nav-collapse is used to display mobile menu button. The content available in nav-collapse will not be shown on webpage.
    You can use this code for your menu.

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    
    <nav class="navbar navbar-inverse">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">WebSiteName</a>
        </div>
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Page 1</a></li>
          <li><a href="#">Page 2</a></li>
          <li><a href="#">Page 3</a></li>
        </ul>
      </div>
    </nav>
      
    
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search