473,811 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

img width height attributes vs. inline styles

yb
Hi,

is the following html markup:

<img src="xyz.jpg" width="100" height="100" alt="whatever" />

equivalent to:

<img src="xyz.jpg" style="width : 100px; height : 100px;"
alt="whatever" />

i.e. is setting width and height as attributes for img the same as
setting it in the style sheet?

Thank you.

Oct 21 '05 #1
4 3315
On 21 Oct 2005 13:00:08 -0700, "yb" <ba*********@ya hoo.ca> wrote:
is the following html markup:

<img src="xyz.jpg" width="100" height="100" alt="whatever" />

equivalent to:

<img src="xyz.jpg" style="width : 100px; height : 100px;"
alt="whateve r" />

i.e. is setting width and height as attributes for img the same as
setting it in the style sheet?


Not quite. Often they will produce the same results, but not always.

Firstly, if you have non-zero margin and/or padding set on img elements,
the results may be different (I can't immediately recall which browsers
do what).

Secondly, using the first method enables browsers to quickly render
pages with several images, because they know how much space to reserve.
I don't think this is true of the second method - at least not for all
browsers.

Thirdly, if you have other CSS definitions which interact with these,
they may end up at different positions in the cascade. (I suppose this
may be a generalisation of my first point).

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/
Oct 21 '05 #2
yb wrote:

is the following html markup:
<img src="xyz.jpg" width="100" height="100" alt="whatever" />
equivalent to:
<img src="xyz.jpg" style="width : 100px; height : 100px;"
alt="whatever" />

i.e. is setting width and height as attributes for img the same as
setting it in the style sheet?

AFAIK, yes. Though it is not worth the trouble to put it in a
stylesheet unless it is a repeated feature. For one-off's it's easier and
more versatile to have it in the body.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Oct 22 '05 #3
Stephen Poley wrote:
Not quite. Often they will produce the same results, but not always.


In addition to the points mentioned, there are some other possibilities
for differences:

When style sheets are disabled (or at least the author style sheet is),
the settings in inline styles have no effect of course. The settings in
HTML attributes still take effect (unless the browser gets formal and
thinks that presentational attributes need to be really mapped to
corresponding CSS rules).

Some programs that filter out images based on their dimensions
(detecting e.g. common ad sizes) may simplistically look at information
at the HTML level only (because parsing and interpreting CSS is much
more work).
Oct 22 '05 #4
yb wrote:
is the following html markup:

<img src="xyz.jpg" width="100" height="100" alt="whatever" />

equivalent to:

<img src="xyz.jpg" style="width : 100px; height : 100px;"
alt="whatever" />

i.e. is setting width and height as attributes for img the same as
setting it in the style sheet?


Setting it via (X)HTML, rather than CSS, is the only way to ensure the page
layout remains "still" as downloading occurs. This might only be apparent
with a page with a number of images.

It is often claimed, eg as Stephen Poley did in an earlier post, that
explicitly setting the dimensions (in XTHML) gives speedier rendering of the
page. However, my crude experiments in IE6 and Firefox 1.x showd this to be
negligible.

Oct 23 '05 #5

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

Similar topics

23
18667
by: MattB | last post by:
Hello please help, I have a table cell with a div in it. The div has a width of 300px. but when it is rendered it puts extra space into the table cell. Here's the style <style> #treecontainer {
1
3414
by: Jens | last post by:
An image like this one <html> test1<img src="" style="width:100;height:100"/>test2 </html> is in line with the text and has a width and height. How can I get the same with a span or div instead of an image? This does NOT work: <html>
2
16836
by: Clemens Quoss | last post by:
Hello, I just encountered a strange thing when switching the doctype on and off in the following html testpage (with IE 6.0): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
2
6771
by: Robson Carvalho Machado | last post by:
Dear friends, I'm dynamically creating a Hyperlink with spacer.gif as ImageURL that is an 1px transparent image only to determine link position, but as I create this link dynamically I could not set image width. This problem makes my link clickable only on its borders. When viewing HTML source I could see that spacer.gif has no width and height, so HTML shows only 1px x 1 px image.
2
4826
by: Jeff | last post by:
Using ASP.NET 1.1 I have an <asp:TextBox... for which I set the width property --- "width=30". The textbox is being rendered to the browser like this: <input name="someName" type="text" maxlength="3" id="someID" style="width:30px;" /> Notice the gets rendered as . This causes
7
6315
by: David Trimboli | last post by:
Suppose I've got HTML with the following in it: <ul class="navigation"> <li><a href="chapter1.html" title="Chapter 1">Previous</a></li> <li><a href="./">Contents</a></li> <li><a href="chapter3.html" title="Chapter 3">Next</a></li> </ul> I'd like to style this such that all three links appear on the same line, with Prev at the far left, Contents in the center, and Next at the
31
3117
by: Sarita | last post by:
Hello, this might sound stupid, but I got a really nice homepage template which unfortunately is a 3-Column Fixed Width CSS format. Now I don't have any content for the right column and would like the middle column just to use up that space instead. Any way this is possible? Thanks for your help, it is highly appreciated!
4
39427
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
4
1928
by: Jon | last post by:
Hello all, Would anyone be able to help shed some light on a problem I have with the below site: http://www.maychild.co.uk/consultancy.aspx. It looks fine in IE, but is far to wide in Firefox. I've tried numerous things to amend but no joy - any help would be much appreciated,
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7673
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5561
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.