Reply
Adding Doctype messes my page up :(
Old 09-09-2007, 01:14 PM Adding Doctype messes my page up :(
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
What's up with this? I have this code:

Code:
<html>
<head>
<title>Test</title>
</head>
<body bgcolor=#000000>

<table bgcolor=#000000 height="100%" width="100%" align="middle">
<tr>
<td>
<div align="center"><font color="white" size="30">hello</font></div>
</td>
</tr>
</table>

</body>
</html>
That's the most efficient way I found to center something, but if I add:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
Then the text is no longer centered?! It snaps to the top of the page? Why would adding a Doctype screw up my page?

-Nathan

Last edited by Nathand : 09-09-2007 at 01:15 PM.
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
When You Register, These Ads Go Away!
Old 09-09-2007, 02:38 PM Re: Adding Doctype messes my page up :(
whym's Avatar
Putting food on my family

Posts: 3,429
Name: Daniel
Location: A sleepy town in Mid Wales
Quote:
Originally Posted by Nathand View Post
Why would adding a Doctype screw up my page?
Before you told the browser what Doctype you were using, it assumed you didn't really know what you were doing, so it rendered the page in Quirks mode, where it attempted to interpret the code you wrote.

Once the Doctype was added, the browser decided you probably knew what you were doing and therefore rendered the page to web standards, in Standards mode.

Your best bet is to stop using tables to centralize your content and use divs and CSS to achieve this. This web site should help:

http://dorward.me.uk/www/centre/


Tables weren't designed to be used for styling, and as web standards continue to move on, it's best now to switch to CSS where possible to display styles.
__________________
Whym Web Design - article blog| Personal blog

I need your help - sponsor me!
whym is offline
Reply With Quote
View Public Profile Visit whym's homepage!
 
Old 09-09-2007, 03:59 PM Re: Adding Doctype messes my page up :(
Extreme Talker

Posts: 237
Location: United States
Unfortunately, CSS2 doesn't have a property to vertically center stuff. You might think vertical-align might do it, but it only works for table cells and and inline elements. What you might think you could do instead, is to make the parent element act like a table cell (display: table-cell;) and vertically center it (vertical-align: center;). But it's not really that simple. If you want it to work in IE6 and IE7 without using tables, then you have to use CSS hacks. As far as I know, it's impossible to vertically align most elements without using invalid CSS or tables.

Using the HTML height attribute on a table is not allowed when following the doctype, and that's why your example doesn't work when you add the doctype. There is a workaround though, and the basis of it involves using the CSS height property on your table instead of the HTML attribute.

To center your page with valid CSS and tables: http://apptools.com/examples/tableheight.php

To center your page with CSS hacks and no tables:
http://www.jakpsatweb.cz/css/css-ver...-solution.html
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 09-09-2007, 05:16 PM Re: Adding Doctype messes my page up :(
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
Quote:
Originally Posted by whym View Post
Before you told the browser what Doctype you were using, it assumed you didn't really know what you were doing, so it rendered the page in Quirks mode, where it attempted to interpret the code you wrote.

Once the Doctype was added, the browser decided you probably knew what you were doing and therefore rendered the page to web standards, in Standards mode.

Your best bet is to stop using tables to centralize your content and use divs and CSS to achieve this. This web site should help:

http://dorward.me.uk/www/centre/


Tables weren't designed to be used for styling, and as web standards continue to move on, it's best now to switch to CSS where possible to display styles.
Is it just me or does LadyNRed and the like rub off on everyone on here
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-09-2007, 06:07 PM Re: Adding Doctype messes my page up :(
whym's Avatar
Putting food on my family

Posts: 3,429
Name: Daniel
Location: A sleepy town in Mid Wales
Quote:
Originally Posted by dansgalaxy View Post
Is it just me or does LadyNRed and the like rub off on everyone on here
Lol. Well I support that tables should be used for their correct use (storing data) and not for presentational reasons.
__________________
Whym Web Design - article blog| Personal blog

I need your help - sponsor me!
whym is offline
Reply With Quote
View Public Profile Visit whym's homepage!
 
Old 09-09-2007, 06:41 PM Re: Adding Doctype messes my page up :(
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
You seriously dont know how much you should like LNR XD Lol
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-09-2007, 09:16 PM Re: Adding Doctype messes my page up :(
LadynRed's Avatar
Super Moderator

Posts: 6,743
Location: Tennessee
He can sound like me all he wants to
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!
"Using or working with IE is like having to wear a 1970's polyester suit with pantyhose and a girdle, to work everyday"
Carolina Corvette Club
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 09-10-2007, 06:35 AM Re: Adding Doctype messes my page up :(
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
Haha! LOL i know, sorry LNR its jsut everybody talks about it reminds me of you kinda weird?

Dan D
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Adding Doctype messes my page up :(
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15562 seconds with 12 queries