krow Posted April 8, 2013 Report Share Posted April 8, 2013 (edited) 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 April 8, 2013 by krow Link to comment Share on other sites More sharing options...
newseed Posted April 8, 2013 Report Share Posted April 8, 2013 The proper way is to set it using either width or height...not both. Don't use max-width or max-height. Link to comment Share on other sites More sharing options...
krow Posted April 8, 2013 Author Report Share Posted April 8, 2013 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 More sharing options...
newseed Posted April 8, 2013 Report Share Posted April 8, 2013 #container img {height: 100px;} Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now