Twitter Bootstrap Responsive Background-Image inside Div

HtmlCssTwitter BootstrapTwitter Bootstrap-3

Html Problem Overview


How i can modify #bg image so it would be responsive, resizable and proportional in all browser?

HTML:

 <div class="container">
       <div class="row">
          <div class="col-md-2"></div>

        	<div class="col-md-8 col-sm-6 col-xs-12 well" id="bg">

               </div>

        	<div class="col-md-2"></div>
       </div>
  </div>

css:

@import url('bootstrap.min.css');

body{
	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;
  	margin-top: 12%;	
}

#bg{
	background:url('../img/con_bg4.png') no-repeat center center;
	height: 500px;
}

Html Solutions


Solution 1 - Html

I found a solution.

background-size:100% auto;

Solution 2 - Html

You might also try:

background-size: cover;

There are some good articles to read about using this CSS3 property: Perfect Full Page Background Image by CSS-Tricks and CSS Background-Size by David Walsh.

PLEASE NOTE - This will not work with IE8-. However, it will work on most versions of Chrome, Firefox and Safari.

Solution 3 - Html

Try this (apply to a class you image is in (not img itself), e.g.

.myimage {
  background: transparent url("yourimage.png") no-repeat top center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: 100%;
  height: 500px;
}

Solution 4 - Html

I had the similar issue and i solved it using:

background:url(images/banner1.png) no-repeat center top scroll;
background-size: 100% auto;
padding-bottom: 50%;

... here i had to add the padding: 50% because it wasn't working for me otherwise. It allowed me to set the height of container, as per the size ratio of my banner image. and it is also responsive in my case.

Solution 5 - Html

I believe this should also do the job too:

background-size: contain;

It specifies that the image should be resized to fit within the element without losing it's aspect ratio.

Solution 6 - Html

The way to do this is by using background-size so in your case:

background-size: 50% 50%;

or

You can set the width and the height of the elements to percentages as well

Solution 7 - Html

This should work

background: url("youimage.png") no-repeat center center fixed;
-webkit-background-size: 100% auto;
-moz-background-size: 100% auto;
-o-background-size: 100% auto;
 background-size: 100% auto;

Solution 8 - Html

Don't use fixed:

.myimage {
   background:url(admin-user-bg.png) no-repeat top center;
   background: transparent url("yourimage.png") no-repeat top center fixed;
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: 100%;
   height: 500px;
}


Solution 9 - Html

Mby bootstrap img-responsive class is you looking for.

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
QuestionvkatsitadzeView Question on Stackoverflow
Solution 1 - HtmlvkatsitadzeView Answer on Stackoverflow
Solution 2 - HtmldoodeliciousView Answer on Stackoverflow
Solution 3 - HtmlJowita EmbertonView Answer on Stackoverflow
Solution 4 - HtmlMashhoodView Answer on Stackoverflow
Solution 5 - HtmlKevinAduView Answer on Stackoverflow
Solution 6 - HtmlHive7View Answer on Stackoverflow
Solution 7 - HtmlJayView Answer on Stackoverflow
Solution 8 - HtmlRayKechView Answer on Stackoverflow
Solution 9 - HtmlDzintarsView Answer on Stackoverflow