472,110 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

fixed image size

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
3 21542
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
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
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.

Similar topics

179 posts views Thread by SoloCDM | last post: by
98 posts views Thread by Pamel | last post: by
2 posts views Thread by Danny | last post: by
7 posts views Thread by finecur | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.