Jump to content

How to dynamically resize image in css?


Recommended Posts

I have a simple html + css page that has 3 images on it. I'm trying to make the page resize depending on the size of the browser window. Right now, I have the 3 images in a div that is set to a height as a percentage of the surrounding containers, and the images are set to height:100% and width:auto. now, that works fine if you resize the entire window- but if you only change the width, they won't resize of course since the height didn't change, and they end up getting pushed down the page which is really ugly. my first question: is there a good way to make the images resize no matter if you change the height OR width of the browser using just html/css? If not, should I be using jquery and if so can you point me to a good resource? Second question: if it's not possible, how do I at least stop them from getting bumped down a line? I tried making the overflow hidden or scrolled, but they still get bumped, then either cut off your you have to scroll vertically. Here's a link to the live page: http://carissalyn.com/Landing.html (yes I realize the images load slowly I'll compress them before it's live). Let me know if you need any other info. Here's the relevant css (img container is inside fadingtext which is inside body):

body,html{height:100%;margin:0; padding:0;} #imgcontainer{height: 100%;width: 90%;display: inline-block;}img {max-height:90%;width: auto;}#fading_text {text-align: center;height: 60%;-webkit-animation: fade-text 20s 1;-moz-animation: fade-text 20s 1;}

And here's the relevant html to clarify that there are 3 images:

<div id="fading_text"><div id="imgcontainer"><a href="" class="imghover"><img src="images/leaf.jpg" alt="portrait" class="border"></a><a href="" class="imghover"><img src="images/DSC_2280-Edit-Edit-Final.jpg"  alt="portrait" class="border"></a><a href="" class="imghover"><img src="images/DSC_2685.jpg" alt="blog" class="border">  </a></div></div>

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

  • Create New...