You are here: Re: Why is the table less wide than the div when they both have the same width? « HTML « IT news, forums, messages
Re: Why is the table less wide than the div when they both have the same width?

Posted by Rik on 06/24/06 12:06

dorayme wrote:
> Put this up on a server or else try to validate it... it has
> invalid property values ("hand" ????), you have dashes in things
> between b and ackground-color etc etc. Sharpen yourself up young
> man.

I think those dashes are created in posting, not in the actual content.
Anyway, to the op: when asking question, try to reproduce your 'error' in
the least amount of code.

In this case:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>asdlk</title>
</head>
<body>
<table style="border:1px solid black;width:99%;">
<tr>
<td>More Search Options</td>
</tr>
</table>
<div style="border:1px solid black;width:99%;">
blaat
</div>
</body>
</html>

The problem here is that the border taken into account for the table when
deciding the width, and added to the div element after the width has been
decided. So the div will always be 2*border-width bigger. One should work
with a percentual border in this case, and adjust one elements width to that
percentage. That's badly supported though, and will result in disappearing
borders on low resolutions.

My workaround:
- display both as block
- don't give the elements that width, arrange it in <body> (or another
containing element), or give left- and rightmargin.

So either:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>asdlk</title>
<style type="text/css">
html, body{
width:100%:
}
body{
margin:0;
padding: 0 0.5%;
}
</style>
</head>
<body>
<table style="border:1px solid black;display:block;">
<tr>
<td style="background-color:white;">More Search Options</td>
</tr>
</table>
<div style="border:1px solid black;">
blaat
</div>
</body>
</html>

Or:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>asdlk</title>
<style type="text/css">
html, body{
width:100%:
padding:0;
margin:0;
}
</style>
</head>
<body>
<table style="border:1px solid black;display:block;margin:0 0.5%;">
<tr>
<td style="background-color:white;">More Search Options</td>
</tr>
</table>
<div style="border:1px solid black;margin:0 0.5%;">
blaat
</div>
</body>
</html>

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация