Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive Bootstrap Jumbotron Background Image

I'm using bootstrap jumbotron, and including a background image. Resizing the screen makes the image tile and repeat, whereas I want the image to be responsively resized.

<div class="jumbotron" style="background-image: url(http://www.californiafootgolfclub.com/static/img/footgolf-1.jpg); background-size: 100%;">    <div class="container for-about">    <h1>About</h1>    </div> </div> 

How would you go about making the image responsive? The site is HERE. Thanks for your ideas!

like image 389
Nick B Avatar asked Feb 24 '14 22:02

Nick B


People also ask

How do I fit a background image in a jumbotron?

Answer 55fbcf1f9113cbf0cb0005bf. Hi, you can use a property called background-size: cover; which should pull it across the whole background, it will cut off part in the width or height to fit it inside the area though.

How do I add a background image to a container 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.


2 Answers

The simplest way is to set the background-size CSS property to cover:

.jumbotron {   background-image: url("../img/jumbotron_bg.jpg");   background-size: cover; } 
like image 69
Steve Avatar answered Oct 07 '22 11:10

Steve


This is what I did.
First, just override the jumbotron class, and do the following:

.jumbotron{     background: url("bg.jpg") no-repeat center center;      -webkit-background-size: 100% 100%;     -moz-background-size: 100% 100%;     -o-background-size: 100% 100%;     background-size: 100% 100%; } 

So, now you have a jumbotron with responsive background in place. However, as Irvin Zhan already answered, the height of the background still not showing correctly.

One thing you can do is fill your div with some spaces such as this:

<div class="jumbotron">     <div class="container">         About         <br><br><br> <!--keep filling br until the height is to your liking-->     </div> </div> 

Or, more elegantly, you can set the height of the container. You might want to add another class so that you don't override Bootstrap container class.

<div class="jumbotron">     <div class="container push-spaces">         About     </div> </div>  .push-spaces {     height: 100px; } 
like image 30
Fadils Avatar answered Oct 07 '22 09:10

Fadils