Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 and Responsive Background Images?

I'm trying to create a responsive site using Bootstrap that has multiple full-width background images.

Here's a mockup of how it should look:

enter image description here

The idea is for each image to stretch to the width of the browser window, and then the height to be scaled accordingly to preserve the aspect ratio.

I've put up a JSFiddle of what I've got right now:

http://jsfiddle.net/SeFVV/

Currently, I've got multiple <section> tag, and I'm setting a background image with background-size: cover on each:

    #first {
        background: url(http://placehold.it/1350x890/37FDFC/&text=photo1) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        min-height: 800px;
        /*height: 800px;*/
        /*padding-bottom: 200px;*/
    }

As a hack, I'm setting min-width for each so it's not really responsive.

If I don't set min-height, then each simply shrinks to fit the elements inside, which is not what I want.

In a previous question, the answer suggested using multiple Bootstrap containers - are you meant to have multiple container divs normally? Also, that answer didn't really cover how to make it responsive, so that the width would fit, and the heigh would scale to preserve aspect ratio.

like image 365
victorhooi Avatar asked Sep 15 '13 09:09

victorhooi


People also ask

How do you make Images responsive in Bootstrap?

Images in Bootstrap are made responsive with .img-fluid . max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element.

Which Bootstrap class will you use to make Images responsive?

Images in Bootstrap are made responsive with .img-fluid . This applies max-width: 100%; and height: auto; to the image so that it scales with the parent element.


1 Answers

You can use dynamic height of window by adding to your html and body tag height of 100%, and the section tags of the page(where you want to streach the background images).

Example:

html,body,section{height:100%;}

Live Example

like image 132
Elad Shechter Avatar answered Oct 15 '22 00:10

Elad Shechter