Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting background image of a navigation bar - bootstrap

I have problem setting the background image from folder, 'img/flower.jpg'. I tried using the following code in CSS, the image does not show up: However it works if I reference it from a source in internet.

#navigation,.navbar .navbar-default{
  background-image: url("img/flower.jpg");
  background: url('img/flower.jpg');
}



<div class="container">
<!-- Navigation -->
  <nav class="navbar navbar-default " id="navigation" role="navigation">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            Jeen's Portfolio 

        </div> 
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
  </nav> 
</div>

/* CSS used here will be applied after bootstrap.css */
#navigation,.navbar .navbar-default{
  border-top: 2px dotted blue;
  border-bottom: 2px dotted blue; 
  background-image: url("http://upload.wikimedia.org/wikipedia/commons/6/6b/Bubble_3.jpg");

  background: url('http://upload.wikimedia.org/wikipedia/commons/6/6b/Bubble_3.jpg');
 font-style: zapfino;
}

Demo

like image 889
user21 Avatar asked Apr 14 '15 04:04

user21


People also ask

How do I add an image to a navigation bar?

We just need to add a div tag with the class as a container and put the navbar-brand(image or logo) inside this div. After that, we just need to add the class mx-auto to the navbar-brand class.

How do I add a background image in bootstrap?

Just add . bg-img class on your <img> element and .has-bg-img class to parent element that you want to apply a background image. Images are part of the DOM and are transformed into CSS background-image after they are fully loaded.

How do I add background color to navigation bar?

Use any of the . bg-color classes to add a background color to the navbar.


2 Answers

This can better if you can show your folder structure for the images and the style file or if possible give the url.your img folder should be in same directory in which your style file exists .then this will work .

#navigation,.navbar .navbar-default{
  background-image: url("img/flower.jpg");
}

or if it is in some other directory find the path with the use of ../ . this denote that you are one step back from the directory . like this

#navigation,.navbar .navbar-default{
      background-image: url("../img/flower.jpg"); /* assuming img folder is one step back from css*/
    }
like image 174
Manoj Dhiman Avatar answered Sep 27 '22 19:09

Manoj Dhiman


background-image: url('/img/flower.jpg');

background-image: url('http://upload.wikimedia.org/wikipedia/commons/6/6b/Bubble_3.jpg');

like image 43
wijaya Avatar answered Sep 27 '22 20:09

wijaya