By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,494 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,494 IT Pros & Developers. It's quick & easy.

fixed image size

P: n/a
I have a <img scr="mypic.jpg"in my html. I would like to display the
image by width=200 if the image width is larger than 200. I also would
like to display the image by its real width if the image width is
smaller than 200. How can I do it?

Thanks,

qq

Feb 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2007-02-12, finecur <fi*****@yahoo.comwrote:
I have a <img scr="mypic.jpg"in my html. I would like to display the
image by width=200 if the image width is larger than 200. I also would
like to display the image by its real width if the image width is
smaller than 200. How can I do it?
img { max-width: 200px; }
Feb 12 '07 #2

P: n/a
Ben C wrote:
>
img { max-width: 200px; }
If you're going to do this, you might want to omit setting the height
attribute in the img element, so it will scale correctly. Otherwise,
you'll get a distorted image.

--
Berg
Feb 12 '07 #3

P: n/a
Scripsit finecur:
I have a <img scr="mypic.jpg"in my html.
You should fix the markup then (at least by adding an alt attribute).
I would like to display the
image by width=200 if the image width is larger than 200. I also would
like to display the image by its real width if the image width is
smaller than 200. How can I do it?
Although you can do that as others have replied, using the max-width
propertym though not for IE 6 or older, it's almost always a wrong idea to
do such things via markup or style sheets. The image should be converted to
a suitable size on the server or before it is uploaded onto the server, for
two basic reasons:
1) More efficient - it's foolish to transfer a large image and then have it
shrinked, losing much of its quality that required so many bytes.
2) Better quality - browsers aren't really good image processing software.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Feb 13 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.