Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text in Tables

Status
Not open for further replies.

MysticCatcher

Programmer
Sep 2, 2003
6
US
I'm trying to put text in a table, one which has a background, but when I try, it always puts it outside my table. Here is my code....
[tt]<tr height=&quot;15&quot;>
<td width=&quot;299&quot; height=&quot;15&quot;><img border=&quot;0&quot; src=&quot;spacer.bmp&quot; width=&quot;299&quot; height=&quot;15&quot;><-- Here is where I want my text. At the very right end of this table data.</td>
<td width=&quot;270&quot; height=&quot;15&quot;><img border=&quot;0&quot; src=&quot;spacer2.bmp&quot; width=&quot;270&quot; height=&quot;15&quot;></td>[/tt]
 
For starters, I don't particularly like the use of 'spacer' gifs for positioning. You can use the padding-left CSS attribute if you want some space before the text.

Try:
[tt]
<tr height=&quot;15&quot;>
<td style=&quot;padding-left:299px;&quot;>Some text Here</td>
<td style=&quot;padding-left:270px;&quot;>Some Text Here</td>
</tr>
[/tt]
 
No, you dont understand. The spacer.bmp is just a small area to seperate the top of my page and the bottom. I Just want to position text in a table, preferably in the center.
 
>>The spacer.bmp is just a small area to seperate the top of my page and the bottom.

Then you have it in entirely the wrong place. Just put the text inside the <td></td> tags. If you want them centred you can either set that using the align attribute of the td - <td width=&quot;299&quot; align=&quot;center&quot;> or CSS.
 
You dont understand once again. I just want to put some text in. What you have told me is incorrect. Lets say I went with the <td width=&quot;43&quot; height=&quot;34&quot;><font.... <--- that does not work.
 
>> What you have told me is incorrect

What I have told you is perfectly correct and in keeping with the questions you have asked.

Copy the following code, open notepad, paste the code in and save the file as tables.html
[tt]
<html>
<head>
<title>Tables 101</title>
</head>
<body>
<table border=&quot;1&quot;>
<tr>
<td align=&quot;center&quot; width=&quot;300&quot;>
<font face=&quot;Arial, Helvetica, sans-serif&quot; color=&quot;#FF0000&quot; size=&quot;+1&quot;>
This is cell 1
</font>
</td>
<td align=&quot;center&quot; width=&quot;300&quot;>
<font face=&quot;Times New Roman, Times, serif&quot; color=&quot;#0000FF&quot; size=&quot;+2&quot;>
This is cell 2
</font>
</td>
</tr>
<tr>
<td align=&quot;center&quot; width=&quot;300&quot;>
<font face=&quot;Courier New, Courier, mono&quot; color=&quot;#FF00FF&quot; size=&quot;+3&quot;>
This is cell 3
</font>
</td>
<td align=&quot;center&quot; width=&quot;300&quot;>
<font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; color=&quot;#00FF00&quot; size=&quot;+4&quot;>
This is cell 4
</font>
</td>
</tr>
</table>
</body>
</html>
[/tt]


There are plenty of beginners HTML references available on the web. I'd suggest checking out or Other than that
 
OK, now I more clearly see what you're doing.

Using images like that is not really the best way of doing things. Images are very bulky to download (spacer, nav and main alone were 693 kilobytes - my whole example below is only 815 bytes)

One of the fundamental principles of any programming is that the data should be as independent of the design as possible. HTML is slack, because it allows the mixing and matching of design elements and data elements.

CSS helps out by separating some of the design (how things should look) from the data (what those things are)

Have a play with the following code and you'll see what I mean:
[tt]
<html>
<head>
<title>Tables 102 - Using CSS</title>
<style type=&quot;text/css&quot;>
.mainTable {
width:569px;
border: 1px solid #000000;
height: 415px;
border-collapse: collapse;
}
.spacerCell {
width: 569px;
height: 15px;
border-bottom: 2px solid #000000;
background: #7CC4F8;
padding: 0px;
margin: 0px;
}
.navCell {
width: 150px;
height: 400px;
border-right: 1px solid #000000;
background: #B6E9FC;
}
.mainCell {
width: 419px;
height: 400px;
background: #EEEEF2;
}
</style>
</head>
<body>
<table class=&quot;mainTable&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr height=&quot;15&quot;>
<td class=&quot;spacerCell&quot; colspan=&quot;2&quot;></td>
</tr>
<tr>
<td class=&quot;navCell&quot;></td>
<td class=&quot;mainCell&quot;></td>
</tr>
</table>
</body>
</html>
[/tt]
 
I still dont have a clue how to put some text into tables!! Personaly, I liked my idea with the tables. But if anyone can help me I'd love it...Sorry Dwarf, but your not explaining it.
 
It's I who should be sorry if I'm not explaining things very well.

Firstly, I'd reitterate my position on getting some resources to help you learn HTML. A forum like this is useful for nutting out a particular issue you might be having, but it's not the best way to learn. Look for books or websites that have both tutorial (this will show you the techniques to use) and reference sections (this will enable you to look up tags and attributes that you may not have come across previously). In particular I'd recommend taking this tutorial from W3Schools It has a section devoted to tables, several examples and a detailed reference section.

The other way to learn is by copying what you see around you. A huge percentage of web sites use tables in some way shape or form and all that code is available to you by using the &quot;View Source&quot; command on your browser. Find a table you like, view the source, copy the relevant code to one of your own web pages and play around with it.

I'm sorry I haven't been more helpful. If anyone else out there can give some further advice I'm sure it would be appreciated.
 
MysticCatcher

It's not that dwarfthrower isn't explaining it well, he is working with what you have told him and has done a pretty good job at that.

Can you draw the text onto the image where you want it to appear?

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Hi,

First of all you shouldn't be using .bmp images; their file size is way too large and they're not cross-browser compatible. They need to be compressed to .gif or .jpg format, whichever is appropriate for the individual image.

To place text into a cell with a background image (not using css), the html would be:

<table cellspacing=0><tr><td background=&quot;your_background_image.gif&quot; align=center>Your text goes here.</td></tr></table>

Note: If you need to force the cell to be the same height as your background image, you can place a transparent .gif in the cell with the minimum height that you require. For example if your background image was 50 px high:

<table cellspacing=0>
<tr>
<td background=&quot;your_background_image.gif&quot; align=center valign=middle><img src=&quot;transparent_image.gif&quot; width=&quot;1&quot; height=&quot;50&quot;>Your text here.</td></tr></table>

The background image will fill the width of the cell. If it's not wide enough to fill the cell, it will tile to fill it. The align=center aligns the text in the center of the cell horizontally; valign=middle aligns the text in the middle of the cell vertically.

Hope that helps.
 
Slight correction to my previous post. &quot;Valign=middle&quot; inside the <td> tag works to vertically align the text, except in the above case where I used a transparent gif to hold the cell height, you need to specify &quot;align=middle&quot; as part of the image tag; this controls how the text aligns with the image (even though it's transparent) on the same line:

<table cellspacing=0 width=&quot;570&quot;>
<tr><td background=&quot;your_background_image.gif&quot; align=&quot;center&quot;><img src=&quot;transparent_image.gif&quot; height=&quot;50&quot; width=&quot;1&quot; align=&quot;middle&quot;></td></tr></table>

Of course, if you don't need to force the height of your cell beyond the height of your text, then you don't need to use a transparent .gif to control the height.

Here is the corrected code using your very first example:

<tr height=&quot;15&quot;>
<td width=&quot;299&quot; height=&quot;15&quot; background=&quot;spacer.bmp&quot; align=&quot;right&quot;>Here is where I want my text. At the very right end of this table data.</td>
<td width=&quot;270&quot; height=&quot;15&quot;><img border=&quot;0&quot; src=&quot;spacer2.bmp&quot; width=&quot;270&quot; height=&quot;15&quot;></td></tr>

Of course, there are other options using css, but you originally asked about the html.

 
How about telling us what text you want and wher you want it? Without that, I'm as confused as you ass to what you want. From what I've read above and the info ou've provided, the examples given are what you need.



There's always a better way. The fun is trying to find it!
 
I want links in the nav.bmp area, and I want to explain and show what that page has to ofer in the main.bmp area. Thanks to everyone that helped. And I dont really care wether it's CSS or HTML I do the tables with. I dont even know the difference really. The main.bmp is going to have alot of images and info on it while the nav.bmp is just going to have a few links.
 
Ok then... surely you've seen a site or two who's design is reasonably similar to what you hope to achieve. Try going to a couple of those sites and looking at their source code to see how they did it. That will give you some food for thought as to how to go about your implementation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top