How to use responsive background image in css3 in bootstrap

HtmlCssTwitter BootstrapBackground Image

Html Problem Overview


I dont want to use html tag. This is my css. I am using bootstrap 3.0.

background:url('images/ip-box.png')no-repeat;
background-size:100%;
height: 140px;
display:block;
padding:0 !important;
margin:0;

On 100% zoom this is OK. but when I zoom in at 180% approx, the image will be short from top and bottom, I want some css tricks.

Html Solutions


Solution 1 - Html

For full image background, check this:

html { 
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;
}

Solution 2 - Html

You need to use background-size: 100% 100%;

Demo

Demo 2 (Won't stretch, this is what you are doing)

Explanation: You need to use 100% 100% as it sets for X AS WELL AS Y, you are setting 100% just for the X parameter, thus the background doesn't stretch vertically.


Still, the image will stretch out, it won't be responsive, if you want to stretch the background proportionately, you can look for background-size: cover; but IE will create trouble for you here as it's CSS3 property, but yes, you can use CSS3 Pie as a polyfill. Also, using cover will crop your image.

Solution 3 - Html

I found this:

Full

An easy to use, full page image background template for Bootstrap 3 websites

http://startbootstrap.com/template-overviews/full/

or

using in your main div container:

html

<div class="container-fluid full">


</div>

css:

.full {
    background: url('http://placehold.it/1920x1080') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
    height:100%;
}

Solution 4 - Html

Check this out,

body {
	background-color: black;
	background: url(img/bg.jpg) no-repeat center center fixed; 
	-webkit-background-size: cover;
	-moz-background-size: cover;
	-o-background-size: cover;
	background-size: cover;
}

Solution 5 - Html

The file path 'images/ip-box.png' implies that the css file is at the same level as the images folder.

It's probably more common to have 'images' and 'css' folders at the same level as the 'index.html' file.

If that were the case and the css file were one level down in its respective folder, then the path to ip-box.jpg as specified in the css file would be: '../images/ip-box.png'

Solution 6 - Html

Set Responsive and User friendly Background

<style>
body {
background: url(image.jpg);
background-size:100%;
background-repeat: no-repeat;
width: 100%;
}
</style>

Solution 7 - Html

Try this:

body {
  background-image:url(img/background.jpg);
  background-repeat: no-repeat;
  min-height: 679px;
  background-size: cover;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFaizanView Question on Stackoverflow
Solution 1 - HtmlfiskolinView Answer on Stackoverflow
Solution 2 - HtmlMr. AlienView Answer on Stackoverflow
Solution 3 - HtmlradukenView Answer on Stackoverflow
Solution 4 - HtmlLevent DiviliogluView Answer on Stackoverflow
Solution 5 - HtmlwkilleView Answer on Stackoverflow
Solution 6 - Htmlpradip korView Answer on Stackoverflow
Solution 7 - Htmluser6060331View Answer on Stackoverflow