Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap responsive background image

How do I make, using bootstrap, a div holder having as background an image to fit to visitors display? The image has a fixed height and width. If the screen is smaller should be resized to do not have x,y overflow.

like image 791
kakuki Avatar asked Apr 27 '13 08:04

kakuki


3 Answers

You could use background-size like this:

div.someclass {   background-size: cover; } 

There's a good article from @Chris Coyier showing a few techniques: http://css-tricks.com/perfect-full-page-background-image/

like image 147
pzin Avatar answered Sep 19 '22 01:09

pzin


First, for the background image:

div.someclass{   background: url(images/bg.jpg) no-repeat center center fixed;   -webkit-background-size: cover;  -moz-background-size: cover;  -o-background-size: cover;  background-size: cover; } 

This will make your background image responsive, i.e. it will fit according to the size of the display the page is viewed on.

Second, to keep the main form content a proper margin from above on any device is to give the div you just created for the main content a relative margin on top:

div.someclass{  margin-top:5%; } 

change the above 5% according to your requirement.

like image 39
Pranav Pandey Avatar answered Sep 22 '22 01:09

Pranav Pandey


I'm not very experienced in Bootstrap, but I think there is no such feature. I recommend you the create your own "Bootstrap Theme", a pure CSS or LESS file to customize your background.

You could simply use:

body
{
    background: url(https://www.google.hu/images/srpr/logo4w.png);
    background-size: cover;
}

This code stretches your background image in both dimensions, but it cuts some parts of the image, unless the screen ration is the same as the image ratio.

body
{
    background: url(https://www.google.hu/images/srpr/logo4w.png) no-repeat center center fixed;
    background-size: cover;
}
like image 34
kdani Avatar answered Sep 20 '22 01:09

kdani