HTML Query

J

Jon

Hi, I'm pretty good normally with HTML, but for some reason I'm blind as to
why the following code doesn't work:

<html>
<head>
<body topmargin=0 marginheight=0 leftmargin=0>
<table cellpadding=0 cellspacing=0 width=100% border=0>
<tr height=2>
<td bgcolor=black width=100% height=2>
</td>
<td bgcolor=#666666 height=2>
<img src="spacer.gif" width=190 height=2>
</td>
</tr>
</table>
</html>


I simply want a 2 pixel high bar across the screen with the last 190 pixels
being grey and the rest black. spacer.gif is a 1x1 pixel transparent gif.

Instead of being 2 pixels high, it is (I think) 18 pixels high, and I can't
seem to find any way of making it smaller.

Cheers
 
N

Nick Howes

<head>
<body topmargin=0 marginheight=0 leftmargin=0>
<table cellpadding=0 cellspacing=0 width=100% border=0>
<tr height=2>
<td bgcolor=black width=100% height=2>
</td>
<td bgcolor=#666666 height=2>
<img src="spacer.gif" width=190 height=2>
</td>
</tr>
</table>
</html>

I can't vouch for other browsers, you'd have to try it, but in IE6 it works
to keep each cell on one line with no gaps like so:

<td bgcolor=black width=100% height=2></td>
<td bgcolor=#666666 height=2><img src="spacer.gif" width=190
height=2></td>

because line breaks and returns are often interpreted as a single space
character (intented so that you can put line breaks in a paragraph of text
to keep your source looking neat), which will try to fit in the table thus
stretching it vertically.
 
D

Dan Brussee

Hi, I'm pretty good normally with HTML, but for some reason I'm blind as to
why the following code doesn't work:

<html>
<head>
<body topmargin=0 marginheight=0 leftmargin=0>
<table cellpadding=0 cellspacing=0 width=100% border=0>
<tr height=2>
<td bgcolor=black width=100% height=2>
</td>
<td bgcolor=#666666 height=2>
<img src="spacer.gif" width=190 height=2>
</td>
</tr>
</table>
</html>


I simply want a 2 pixel high bar across the screen with the last 190 pixels
being grey and the rest black. spacer.gif is a 1x1 pixel transparent gif.

Instead of being 2 pixels high, it is (I think) 18 pixels high, and I can't
seem to find any way of making it smaller.

I agree with the other poster - keep the <td> and </td> on the same line
with no gaps. A new line in HTML is treated as a space, so you are
forcing the td height to be at least as tall as a character in the font
chosen.
 
R

Robert Frost-Bridges

R

Richard

Jon said:
Hi, I'm pretty good normally with HTML, but for some reason I'm blind as to
why the following code doesn't work:

<html>
<head>
<body topmargin=0 marginheight=0 leftmargin=0>
<table cellpadding=0 cellspacing=0 width=100% border=0>
<tr height=2>
<td bgcolor=black width=100% height=2>
</td>
<td bgcolor=#666666 height=2>
<img src="spacer.gif" width=190 height=2>
</td>
</tr>
</table>
</html>


I simply want a 2 pixel high bar across the screen with the last 190 pixels
being grey and the rest black. spacer.gif is a 1x1 pixel transparent gif.

Instead of being 2 pixels high, it is (I think) 18 pixels high, and I can't
seem to find any way of making it smaller.

Cheers

Why do you have cell #1 width set to 100%??
You declared the base of the table width to 100% in the <table> tag.
So by declaring the #1 cell also to 100%, cell #2 has nothing to use.
That could be what's driving the spacer height up to 18 pixels.
It has nowhere to go.
As a test, change the cell#1 width to 50% and see what happens.
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top