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

x
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
http://codepen.io/chooch/pen/JROAjy

http://www.w3schools.com/cssref/css3_pr_background-size.asp

set the following

   background-size: contain;
  background-repeat: no-repeat;
  height:100px;
 

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

This makes the image fit its container.
<!doctype html>
<html>
<head>
<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;
}
</style>
</head>
<body>
</body>
</html>

Open in new window

Here is a working sample
0

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
0
lenamtlCommented:
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

0
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:

Split:
-- 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.

mplungjan
Experts-Exchange Cleanup Volunteer
0
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
CSS

From novice to tech pro — start learning today.