473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Your opinion please: image width and height (in CSS) in em or percent

Hi,

Your opinion please on the following subject: Is it acceptable to set
the width and height of an image in ems or percents in CSS?

The advantage for me is that images will scale up or down when the user
changes the font size in the browser. But what of the disadvantages?

In (X)HTML, the img-element will have a pixel-value for the width and
height-attributes.
The body CSS-style will have a font-size set, eg 12px, and the image
sizes in CSS are calculated relative to the font size, so that an image
of 120px by 60px becomes 10em by 5em. (Similar conversion in percent,
but not yet tried.)

So if we have an img-element with id="myPicture", the CSS-style would be

#myPicture {
width: 10em;
height: 5em;
}

There seem to be problems with this in IE6 (IE7 not yet tested), but
I'm looking at a workaround. In order to avoid needless work, I'll
rephrase my question: Are there reasons not to have scaleable images
(with CSS) in a page, other than pixelation effects?

Thanks for reading up to here and I welcome your feedback.

Best Regards,

Stef
Jun 24 '07 #1
6 4782
On 6/24/2007 11:19 AM, Stephan Bourdon wrote:
Hi,

Your opinion please on the following subject: Is it acceptable to set
the width and height of an image in ems or percents in CSS?

The advantage for me is that images will scale up or down when the user
changes the font size in the browser. But what of the disadvantages?

In (X)HTML, the img-element will have a pixel-value for the width and
height-attributes.
The body CSS-style will have a font-size set, eg 12px, and the image
sizes in CSS are calculated relative to the font size, so that an image
of 120px by 60px becomes 10em by 5em. (Similar conversion in percent,
but not yet tried.)

So if we have an img-element with id="myPicture", the CSS-style would be

#myPicture {
width: 10em;
height: 5em;
}

There seem to be problems with this in IE6 (IE7 not yet tested), but
I'm looking at a workaround. In order to avoid needless work, I'll
rephrase my question: Are there reasons not to have scaleable images
(with CSS) in a page, other than pixelation effects?

Thanks for reading up to here and I welcome your feedback.

Best Regards,

Stef
If your images are page decorations (e.g., ornamental lines separating
sections of text) or navigation buttons, relative sizing might be a good
idea.

However, I carefully size illustrations needed to help explain concepts
in the text and photographs to fit 800x600 resolution without horizontal
scrolling, even with a vertical toolbar on one side. I then use
absolute sizing. I also use absolute sizing for small images (e.g., a
40x40 px image of a house for a link to return to my home page).

--

David E. Ross
<http://www.rossde.com/>.

Don't ask "Why is there road rage?" Instead, ask
"Why NOT Road Rage?" or "Why Is There No Such
Thing as Fast Enough?"
<http://www.rossde.com/roadrage.html>
Jun 24 '07 #2
Stephan Bourdon wrote:
>
Is it acceptable to set
the width and height of an image in ems or percents in CSS?

what of the disadvantages?
Browsers tend to do a lousy job of scaling images, especially enlarging
them. Images are pixel-based elements, and will always look best when
left at their actual dimensions.

--
Berg
Jun 24 '07 #3
On 2007-06-24, Bergamot wrote:
Stephan Bourdon wrote:
>>
Is it acceptable to set
the width and height of an image in ems or percents in CSS?

what of the disadvantages?

Browsers tend to do a lousy job of scaling images, especially enlarging
them. Images are pixel-based elements, and will always look best when
left at their actual dimensions.
That depends very much on the image. Photographs, especially JPEGs,
often enlarge (and reduce) quite well, even in a browser. It really
depends on the image file in question.

Images with hard-edged lines may not fare as well.

Try your images in various sizes. in various browsers, to see
whether the result is acceptable.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Jun 24 '07 #4
Chris F.A. Johnson wrote:
>>Browsers tend to do a lousy job of scaling images, especially enlarging
them. Images are pixel-based elements, and will always look best when
left at their actual dimensions.


That depends very much on the image. Photographs, especially JPEGs,
often enlarge (and reduce) quite well, even in a browser.
That's valid for all *large* pixel-based images.

Like with fonts, vector-based images are designed for scaled output,
pixel-based images are not.

DoDi
Jun 24 '07 #5
On 24 Jun, 19:19, Stephan Bourdon <stephan.bour...@sintlukas.be>
wrote:
>Is it acceptable to set the width and height of an image in ems or percents in CSS?
Yes, but it will cause scaling, and that's itself bad.

For an "eye candy" image, I'd potentially do this. Most such images
are 1 dimensional anyway and so scale or stretch in the other
dimension without problems. OTOH though, I'd be more likely to display
such an image by use of a CSS background anyway.

For a "content" image, I wouldn't do this, as client-side scaling is
too ugly. Instead I'd use fluid design to reconcile an image in a
fixed pixel size with text sixed in ems.

Jun 25 '07 #6
In article <0r******************************@iswest.net>,
"David E. Ross" <no****@nowhere.notwrote:
On 6/24/2007 11:19 AM, Stephan Bourdon wrote:
Hi,

Your opinion please on the following subject: Is it acceptable to set
the width and height of an image in ems or percents in CSS?

The advantage for me is that images will scale up or down when the user
changes the font size in the browser. But what of the disadvantages?
[snip]
If your images are page decorations (e.g., ornamental lines separating
sections of text) or navigation buttons, relative sizing might be a good
idea.

However, I carefully size illustrations needed to help explain concepts
in the text and photographs to fit 800x600 resolution without horizontal
scrolling, even with a vertical toolbar on one side. I then use
absolute sizing. I also use absolute sizing for small images (e.g., a
40x40 px image of a house for a link to return to my home page).
For some images, I've had good results using % sizing. One caveat: I
deliberately made the images larger than needed to "fit" in the layout
using default browser settings at 640x480. I also use a very limited
colour palette, and avoid gradients. For illustrations, I follow
the same route as David Ross. Sometimes, I'll use a smaller version and
link it to a high resolution version (depends on what the image is there
for.)
Jun 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ok | last post by:
Hello, Q: How do I get image width and height before uploading an image? This because, I want to restrict people uploading huge files. Thanks in advance
7
by: Premshree Pillai | last post by:
Hello, Is there a Py module available using which I can find the width and height of any image format? -Premshree ===== -Premshree http://www.qiksearch.com/]
22
by: owen | last post by:
I have been developing web-based applications for around 3 years, first using ASP, and more recently, ASP.NET. I am starting to wonder if web applications are really the way forward for...
19
by: Lisa Jones | last post by:
Hi I don’t want to change my name or anything :) but I wish I was able to save Sound into SQL server and retrieve it So my question is How do you save a wav file into a SQL server and how do...
20
by: C# Beginner | last post by:
I'm currently creating a database class, which contains a member called Open(). With this method users can open different databases. When a user tries to open a database which happens to be secured...
1
by: emilmgeorge | last post by:
Pls somebody give me the code for getting the height and width of a image in pixels in javascript or asp. Thanks - Emil
1
epots9
by: epots9 | last post by:
I have a image inside of a div <div id="image"> <div id="loader"> <img id="loaderImage" src="assets/loader.gif" alt="loading..." /> </div> <div id="loaded"> <img id="picture" src="" alt=""...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.