CSS Image background image with bootsrap

I am using bootstrap and with an image, you can use class img-responsive to make the image responsive. How can this be done if you are using a css background image.
Paul De LagraveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PawełI Design & Develop SoftwareCommented:
check out the following


set the following

   background-size: contain;
  background-repeat: no-repeat;

by setting the background-size to contain you're image will scale to fit the container without getting distorted
Julian HansenCommented:
you need to use the background-size: cover style

This makes the image fit its container.
<!doctype html>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
body, html {
	height: 100%;
	width: 100%;
body {
	background: url(images/background4.jpg) no-repeat center center;
	background-size: cover;

Open in new window

Here is a working sample

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Cover vs contain
Cover means the entire element is filled with the image - cropping length or width to ensure it fits.
Contain means you see the whole image but there might be a gutter horizontally / vertically.

The first expands the image until the last border of the image reaches a border of the container
The second expands the image until the first border of the image reaches a border of the container
You better not use any width, height, or margins for that image.

If you decide to use cover
background-size: cover;

Open in new window

use also this
background-attachment: fixed;

Open in new window

Michel PlungjanIT ExpertCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

-- Julian Hansen (https:#a41827544)
-- Paweł (https:#a41827515)
-- lenamtl (https:#a41835880)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.