HTML Formatting in .NET 2.0

A

Arthur Dent

Hello all, ive been programming with ASP.NET since it came out, but am just
getting my feet with now with v.2.
Ive noticed something strange in the way my HTML tables get rendered with 2.

I use tables to layout my pages, doing three rows, a header, content and
footer. When i do this, i make the tables height=100%,
so the footer always shows up at the very bottom of the page.

With 2.0/2005 though, when it renders the pages, it doesnt actually render
at 100% height (even though the code is in the ViewSource of the page).
the table only goes as high as the content forces it, as if the height were
not set at all.

Ive traced it to this line put in by the designer:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Is there a way to turn this off, so the designer doesnt put this line out,
so that my tables will render properly? I tried using the Insert Table
wizard, and specifying the height of 100% but it the same problem as
manually coding it.

Oh, also, it tells me the "align" attribute is obsolete on the table tag,
and i should use the newer construct, but it doesnt tell me what that is...
what is considered the "right" way to align a table in the center of the
page now?

Thanks in advance,
Arthur Dent
 
K

Kevin Spencer

Tools|Options|TextEditor|HTML|Validation is where you can turn this off.

You should be aware, though, that the reason this is used is because XHTML
will eventually supercede HTML on the WWW. This is a good thing. HTML has
become increasingly complex and unpredictable across many browsers. The
formatting rules for it are not strict enough, and it is not easily
extensible. XML in general, and XHTML specifically, are much more extensible
than HTML. XML follows some very strict but simple formatting rules. For
example, elements can not overlap. Opening tags must always be followed by
closing tags. Attributes must always be quoted. These things will eventually
cause all browsers to render content in the same way. But some things you
are now doing may not work correctly in browsers in the future. Learning the
XHTML standard, or at least the transitional standard, will prevent a lot of
future headaches for you, though they may cause you a few in the short run
(learning them, that is).

XHTML relies on styles almost exclusively, rather than attributes. This is
also a good thing. Putting CSS styles into an external style sheet, or at
least in a style sheet in the <head> of the document separates the layout
presentation rules from the HTML objects themselves, which makes it much
easier to change the way your documents look. Inline attributes (and inline
CSS styles) "lock" the appearance into the structure of the object, making
it difficult to find, identify, and change the way the elements look and
behave. The use of external CSS style sheets also allows you to use the same
style sheet for many documents, which is also a very good thing.

Many attributes are already deprecated. The "height" attribute has not been
a part of the standard since at least HTML 3.2, and I'm not sure if it ever
was. The "width" attribute of a table has been recently deprecated. All of
this is heading towards the use of CSS for this type of thing.

So, I gave you the means to turn it off, and a few reasons not to. Now the
ball is in your court!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Arthur Dent

Okay, i understand all that, and it makes sense. And given that i would
agree it would be
better to find the "new & improved" way of styling my tags as opposed to
turning off the
validation tag.
I still have some questions then though about the specific styles of HEIGHT
and ALIGN.

HEIGHT does not seem to do anything even when i put it in the style of the
object instead
of as its own attribute. My footer (which i want to always be at the bottom
of the page)
winds up scrunched as close to the top of the page as possible (base on
current cotent of
the table). So how do i tell the new XHTML that i want my table to stretch
itself to the full
height of the document?

Also, what is the proper way to align the table in the center of the page. I
personally cannot
stand when a web page hangs off to the left side of the screen, so i would
always put on my
main table an ALIGN=CENTER, so that it would be in the middle of the page.
But this is
gawked at by the IDE, and i tried doing an ALIGN: CENTER in the style
instead but it had
no effect.

Also, does it _functionaly_ make a difference whether the style definition
is in a CSS vs.
a STYLE tag in the document vs. a STYLE attribute on the element?

Thanks in advance,
- Arthur Dent.
 
K

Kevin Spencer

Hi Arthur,

As to height, you can use the CSS height style, which can be one of 2
alternative types:

nnnPX;
nnn%;

For center alignment, it's a little less intuitive. You use both margin-left
and margin-right, as in:

margin-left:auto;
margin-right:auto;
Also, does it _functionaly_ make a difference whether the style definition
is in a CSS vs.
a STYLE tag in the document vs. a STYLE attribute on the element?

Not functionally, no. However, here are the advantages of each:

inline: None. Almost as bad as attributes.
document style sheet: Styles may be used throughout the document. Less text,
less redundancy, less points for you to make a mistake and forget or omit
something. Easier to change the style of the document, as the style sheet is
easy to find.
external style sheet: All the advantages of a document style sheet, but you
can also use the same styles for multiple pages.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Arthur Dent

Thanks for the info.... that center alignment DEFinitely, like you said, is
not intuitive. But it did
work perfectly.

I still cannot get the height to work properly though. With the validation
line in the HTML source,
the rendering completely ignores the HEIGHT specification on my table,
whether i do it as a style
attribute, a document style tag, or through a css class. But if i take out
the validation line, then the
height renders completely perfectly as expected.
The problem then though is, if i take out that validation like, then the
margin-[left|right]:auto to do
center alignment no longer works.

How do you get the HEIGHT of a table set at 100% to *actually* render as
100% height in the
new XHTML world???

Thanks in advance,
- Arthur Dent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top