Reputation: 2329
I have made a code to resize and set the width of an image to that of the browser dynamically, so I have set the following code in css
max-width: 100%;
height: auto;
My challenge is that the image never resizes dynamically to occupy the entire screen width of the browser dynamically. Here is a Plnker I have made http://plnkr.co/edit/j6JBCaKBmVQV1PDAh3dZ?p=preview What could be wrong.
Upvotes: 1
Views: 3532
Reputation: 109
Use the property for img.
CSS:
img {
width: 100%;
height: auto;
}
or max-width:100%; it will automatic become resizeable.
Upvotes: 0
Reputation: 5919
To squeze it if the parent becomes too small:
display: block;
max-width: 100%;
height: auto;
To force it taking up the whole with:
display: block;
width: 100%;
height: auto;
Upvotes: 1
Reputation: 4507
Change max-width
to width
.
As should be obvious from the naming, max-width
only acts as an upper limit. It does not make anything bigger, it merely downsizes things if they already are bigger than what you specify there.
Sample: http://jsfiddle.net/b18axhzg/
HTML:
<img src="http://lorempixel.com/400/200/" alt="">
CSS:
img {
width: 100%;
height: auto;
}
Upvotes: 4