469,356 Members | 2,666 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

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 21120
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
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.