• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 61
  • Last Modified:

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.
0
Paul De Lagrave
Asked:
Paul De Lagrave
3 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now