Media-Ed-Online / intro-web-dev-2017aut

Site for course "Introduction to Web Design and Development."
https://media-ed-online.github.io/intro-web-dev-2017aut/
MIT License
12 stars 3 forks source link

Images #73

Open kylakozole opened 6 years ago

kylakozole commented 6 years ago

How do we imbed an image that scales with the size of the window (without distorting) that will max out a certain size? I don't want it to continue to span. Also, how do we determine the exact scale that we set for the image?

JustineEvansUM commented 6 years ago

Hey @kylakozole;

Ideally, you've manipulated your images to the appropriate size before embedding them in your site - for example, you've saved it in PS at 400x400 so you'll embed at width="400" and height="400". However, I'm notorious for sizing in my code too, so you just need to keep the ratios correct and do some math. If you reduce one dimension by 25%, do the same for the other.

If you want to embed an image to size, here's what you can do. Add a style="" attribute to your <img /> element, setting the width=100% with a max size of say, 600px. This means the image will resize with the browser until it hits 600px wide, in which case it'll stop and behave normally.

<img src="..." alt="..." title="..." style="width: 100%; max-width: 600px;" />