Jump to content

Resizing my image proportionally


krow
 Share

Recommended Posts

Hello, I'm kind of stuck here. I managed to resize my image with a fixed div max-width of 960px and it actually works nicely as long as you resize it both vertically and horizontally. It also works when you resize the image horizontally keeping the height constant but it doesn't work the other way around. When I resize it vertically then the image gets cut off. I need the image to resize regardless of whether I'm changing the width or the height. I hope it's clear! I'm leaving the code below for more info. Thanks for the help!

 <!DOCTYPE html><html><head><title>Title of the document</title><style>img {max-width: 100%;height: auto;position:relative;z-index:1000;}#container{max-width:500px}</style></head> <body> <div id="container"><img src="http://4.bp.blogspot.com/-5ZidK4NGC68/TzNOGRrdt8I/AAAAAAAADfU/r7_MCTq0WUA/s1600/Vltava+River,+Prague,+Czech+Republic.jpg" /></div></body> </html>

Edited by krow
Link to comment
Share on other sites

The proper way is to set it using either width or height...not both. Don't use max-width or max-height.
Can you provide an example based on my code? I tried doing what you suggested but I didn't get it to work.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...