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

What's better: attribute or style?

P: n/a
Hi,

Going forward, what's better to use

<td height="20">

or

<td style="height:20;">

Has the time come to put everything into style?

Bura
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Bura Tino" <bu*****@yahoo.com> wrote:
Going forward, what's better to use

<td height="20">

or

<td style="height:20;">


Given these alternatives, definitely the former, since the latter is
incorrect, and the CSS declaration in it shall be ignored by conforming
browsers - but not all browsers conform, so get quite inconsistent behavior.

But neither of them is really adequate. The preferred way is to use external
style sheets, or at least <style> elements, not style attributes. And for
setting a table cell height, you should normally use the em unit, not
pixels. Finally, table cell widths normally shouldn't be set - data tables
usually work best when you leave the width allocation to browsers, and
layout tables shouldn't be used at all. Well, that's the big picture. There
are situations where layout tables still have some justification. But you
were asking a general question, and the general answer is: neither.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #2

P: n/a

"Jukka K. Korpela" <jk******@cs.tut.fi> wrote in message
news:Xn*****************************@193.229.0.31. ..
"Bura Tino" <bu*****@yahoo.com> wrote:
Going forward, what's better to use

<td height="20">

or

<td style="height:20;">
Given these alternatives, definitely the former, since the latter is
incorrect, and the CSS declaration in it shall be ignored by conforming
browsers - but not all browsers conform, so get quite inconsistent

behavior.

Thank you for such an informative answer. I was hoping to receive a short
discussion in the reply but I am a little bit dissappointed that the latter
is incorrect. Would it be possible to ask, what exactly is incorrect about
it?

As far as not using the style attributes, it sounds like an FAQ. Can you
direct me to a discussion on that?

And finally, and perhaps this should be its own thread, but I am trying to
produce html pages that will print nicely, with disjoint tables aligning
properly, predictable page breaks, etc. That is why am specifying height in
pixels. Now I know that ultimately the user can change his/her fonts and
really screw up my intentions. Does that mean that my intention to produce
printable pages flawed by definition?

But neither of them is really adequate. The preferred way is to use external style sheets, or at least <style> elements, not style attributes. And for
setting a table cell height, you should normally use the em unit, not
pixels. Finally, table cell widths normally shouldn't be set - data tables
usually work best when you leave the width allocation to browsers, and
layout tables shouldn't be used at all. Well, that's the big picture. There are situations where layout tables still have some justification. But you
were asking a general question, and the general answer is: neither.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Jul 20 '05 #3

P: n/a
Bura Tino wrote:
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote in message
"Bura Tino" <bu*****@yahoo.com> wrote:
Going forward, what's better to use

<td height="20">

or

<td style="height:20;">


Given these alternatives, definitely the former, since the latter is
incorrect, and the CSS declaration in it shall be ignored by conforming
browsers - but not all browsers conform, so get quite inconsistent
behavior.


Thank you for such an informative answer. I was hoping to receive a short
discussion in the reply but I am a little bit dissappointed that the latter
is incorrect. Would it be possible to ask, what exactly is incorrect about
it?


There's a unit missing. height:20 doesn't say anything about whether
it's pixel, percent, centimeter, etc.

As far as not using the style attributes, it sounds like an FAQ. Can you
direct me to a discussion on that?
I don't think there's a FAQ about it. Inline styles are simply less
"portable" and harder to maintain than external stylesheets.
And finally, and perhaps this should be its own thread, but I am trying to
produce html pages that will print nicely, with disjoint tables aligning
properly, predictable page breaks, etc. That is why am specifying height in
pixels. Now I know that ultimately the user can change his/her fonts and
really screw up my intentions. Does that mean that my intention to produce
printable pages flawed by definition?


Your implementation is flawed, but it's an attempt at working around
current limitations. Considering current browsers and their generally
crappy printing (not to mention horrible support for @media print
properties) there's no "good", working way for printing large HTML
tables. It works marginally better in Word - if the user can work with
Word files at all.
Matthias

Jul 20 '05 #4

P: n/a
Matthias Gutfeldt <sa************@gmx.net> wrote in message news:<bo*************@ID-16734.news.uni-berlin.de>...
Bura Tino wrote:
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote in message
"Bura Tino" <bu*****@yahoo.com> wrote:Going forward, what's better to use

<td height="20">

or

<td style="height:20;">

Given these alternatives, definitely the former, since the latter is
incorrect, and the CSS declaration in it shall be ignored by conforming
browsers - but not all browsers conform, so get quite inconsistent
behavior.
Thank you for such an informative answer. I was hoping to receive a short
discussion in the reply but I am a little bit dissappointed that the latter
is incorrect. Would it be possible to ask, what exactly is incorrect about
it?


There's a unit missing. height:20 doesn't say anything about whether
it's pixel, percent, centimeter, etc.


Good point, thank you.
As far as not using the style attributes, it sounds like an FAQ. Can you
direct me to a discussion on that?
I don't think there's a FAQ about it. Inline styles are simply less
"portable" and harder to maintain than external stylesheets.

Yes, I agree with this point, especially if you write HTML directly.
However, I work almost exclusively with servets. So for me HTML
maintainence is _not_ issue, but java code maintainence _is_. In my
java code, I set the heights and other parameters (like positioning of
divs) in a single logical place so it is very easy to maintain.

With this in mind, is there still anything wrong with using style
attributes?
And finally, and perhaps this should be its own thread, but I am trying to
produce html pages that will print nicely, with disjoint tables aligning
properly, predictable page breaks, etc. That is why am specifying height in
pixels. Now I know that ultimately the user can change his/her fonts and
really screw up my intentions. Does that mean that my intention to produce
printable pages flawed by definition?
Your implementation is flawed, but it's an attempt at working around
current limitations. Considering current browsers and their generally
crappy printing (not to mention horrible support for @media print
properties) there's no "good", working way for printing large HTML
tables. It works marginally better in Word - if the user can work with
Word files at all.


Suppose I don't want to print, but still want things to align nicely.
For example, I want my data table be as tall as a 300x200 image. Is
that doable in a consistent fashion?

Matthias

Jul 20 '05 #5

P: n/a
On Mon, 10 Nov 2003 07:47:51 GMT, "Bura Tino" <bu*****@yahoo.com> wrote:
Going forward, what's better to use

<td height="20">

or

<td style="height:20;">

Has the time come to put everything into style?


Well, answering what I *think* you wanted to ask: yes, the time has come
when it's better to use CSS rather than HTML attributes for layout.
(With the one exception, that I know of, of the height and width
attributes on images, as this assists the browser in laying out the
page.)

As to what you *actually* asked: your first example is better, because
the second is syntactically incorrect. :-/

And further: it's generally better to use an external stylesheet than
actually place styles inline.

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/
Jul 20 '05 #6

P: n/a
In article <b7**************************@posting.google.com >,
bu*****@yahoo.com (Bura Tino) wrote:

:With this in mind, is there still anything wrong with using style
:attributes?

Umm, not sure what you mean. The "style" attribute is okay in xhtml, but
not all attributes are.

The CSS specs <http://www.w3.org/Style/CSS/> allow for using external
stylesheets, or a style declaration in the head element of your
document, or as an element style attribute. It's tidier to use the
external sheets, convenient to use a declaration, and a quick way to get
something done using the attribute. I usually work "upwards" moving the
attributes to a declaration and finally to an external sheet when I'm
happy with the way things are marked up and styled and I've removed all
the redundancies and so forth.

Using styles to center elements (instead of CENTER) and set fonts is
absolutely necessary if you want to validate your document as strict
xhtml. I've found that working to strict xhtml actually makes designing
a page easier, because the rules are concise and everyone agrees on what
they are; also, it throws your user-agent into "standards compliance
mode" which makes for quicker rendering. It's the way of the future, and
I suggest you work towards separating your content from your style.

He said long-windedly ...
--
Looks like more of Texas to me.
.... Arizona, where the nights are warm and the roads are straight.
Jul 20 '05 #7

P: n/a
Matthias Gutfeldt wrote:
As far as not using the style attributes, it sounds like an FAQ.
Can you direct me to a discussion on that?


I don't think there's a FAQ about it. Inline styles are simply less
"portable" and harder to maintain than external stylesheets.


Added to that a simple style="bla" is not media-specific, so when it
comes to the intention of printing that's especially bad.

--
Google Blogoscoped
http://blog.outer-court.com
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.