Creating Tables

dark_fanboy's picture



Well, as promised to Jame I'll be posting how to make those snazzy tables for your guides. For this you're going to need to know a little HTML coding. Thankfully CSS will still work within your HTML codes but you have to be extra careful because if you miss a tag you will botch the entire thing. Trust me, I made a serious error on my last guide and the whole page went funky. Took me an hour to find that missing tag! That said, lets begin.

For those unfamiliar with HTML a good site to check out is www.w3schools.com, there is a link that says Learn HTML on the top left.


First things first! Tags! Tags! TAGS! Pay close attention to your tags. You need an opening tag and a closing tag. Your tags will be surrounded by Angle Brackets < and >. Now you could just drop a table right into your guide but CSS has issues with doing that, or at least it does here. I'm still a novice when it comes to XML and CSS coding so bear with me. Its safer to start AND end your table with an html tag.

Example: < HTML > and < /HTML >

NOTE: When you create your tags there will be no spaces inside the tag, I have to do that here so you can actually see them. Please look at the whiteboard on w3schools.com for a proper representation.

Our opening tag is < HTML > and our closing tag is < /HTML >. The tags are identical except for the forward slash in the ending tag. So your tags will always have a mate, be sure you always have a closing tag! Next comes the BODY tag. The body is what it is, the meat and potatoes or your document.

Example:

<HTML>
<BODY>
</BODY>
</HTML>

Everything will go inside your HTML tags and your displayed material will be inside your BODY tags.

Example:

<HTML>
<BODY>
HI! This is my website. What do you think?
</BODY>
</HTML>

Now try not to get discouraged here, coding is a simple thing. These will be the only HTML tags you will need while building your table. The next set of tags will be a little more complicated but fairly simple. These will be your TABLE tags.

Example:

<HTML>
<BODY>

HI! This is my website. What do you think? Here is a table.<BR>
<TABLE>

</TABLE>

</BODY>
</HTML>

Now, here is where CSS and HTML start to disagree. You'll note that I've added in a tag that I haven't talked about, < BR > is a line break tag and is similar to you hitting Enter on the keyboard. So why not just hit enter? HTML does not recognize word processing line breaks so you have to use the line break tag < BR >. I already have several of these tags listed here but you won't see them at work.

Back to our table. As you create your table you will have to define several things. First are borders. If you do not define the border size you will have a nice neat table but no dividing lines.

Example:

Col1,Row1 Col2,Row1 Col3,Row1
Col1,Row2 Col2,Row2 Col3,Row2

If you wish to create dividing lines you will need to define the border size in your opening TABLE tag.

Example:

< TABLE BORDER="1" >

Col1,Row1 Col2,Row1 Col3,Row1
Col1,Row2 Col2,Row2 Col3,Row2

Now I know I said to never put spaces in your tags, but there will be a few exceptions. Make sure to leave a space between each definition in your tag, such as the one between TABLE and BORDER in the opening table tag.

The BORDER definition tells the browser to load a table border width of 1, a single pixel line usually. You can certainly go higher and you can do some pretty fancy things with your table borders that I will not go in depth here.

Now if you've seen my blacksmithing guide you'll note there is a light gray underline at the top of my table and the text is in bold. This is done by adding a HEADER tag.

Example:

Header1,Col1 Header2,Col2 Header3,Col3
Col1,Row1 Col2,Row1 Col3,Row1
Col1,Row2 Col2,Row2 Col3,Row2

By now you're probably like WHOA NOW! How did you even create the Columns and Rows, you're talking headers and such, I'm so lost! Fret not. Your ROW tags are like BODY tags, everything in that row will be contained within the ROW tag. A ROW tag looks like this: < TR > and a closing tag of < /TR >

Example:

< HTML ><br>
< BODY ><br>

HI! This is my website. What do you think? Here is a table.< BR ><br>
<TABLE BORDER="1">
<TR>
<TD> I'm ROW 1!</TD>
</TR>
</TABLE>

</BODY>
</HTML>

I'm ROW 1!

You're probably wondering what's up with that < TD > tag? That is essentially how we create columns. The < TD > is a Table Data tag. Each time you ad a new < TD > tag you create a new cell of data. You want to make sure that you keep a static number of DATA tags or you will end up with blank cells.

Example:

Col1,Row1 Col2,Row1 Col3,Row1
Col1,Row2 Col2,Row2 Col3,Row2 Col4,Row2
Col1,Row3 Col2,Row3 Col3,Row3

Blank cells aren't the end of the world, but at least your columns are still even. And that is nearly everything.

All we need now are some headers and you're golden. Header tags are simple: < TH > just means Table Header. You can use these to define a bold text and a different shaded underline.

Example:

Header1,Col1 Header2,Col2 Header3,Col3
Col1,Row1 Col2,Row1 Col3,Row1
Col1,Row2 Col2,Row2 Col3,Row2

And you're done! Hopefully I've made this easy enough. If you have any questions please feel free to ask and I'll do my best to answer them in a timely manner as always.



Size is a major factor in life and a factor that I seemed to have missed when creating this guide. Here is an example of how you can use the page width to determine the width of your table. This will assign a maximum width based on the current page width.

Example:

I'm huge!


<html>
<body>
<table border="1" width="100%">
<tr>
<td>I'm huge!</td>
</tr>
</table>
</body>
</html>

Example:

I'm tiny!


<html>
<body>
<table border="1" width="10%">
<tr>
<td>I'm tiny!</td>
</tr>
</table>
</body>
</html>


Comments

kayeich's picture

Anybody know what's up with

Anybody know what's up with tables in the website?

Right now, they always force themselves to be the full width, and it's impossible to make a bordered table of smaller width except by doing a messy/complex nested table.

As an example, the only way to create a 2x2 table of width "300" would be to do:
<table>
<tr><td width="300"><table>
<tr><td width="150">stuff
<td width="150">stuff2
<tr><td>stuff3
<td>stuff4</table>
<td><br></table>

As opposed to a simpler:
<table>
<tr><td width="150">stuff
<td width="150">stuff2
<tr><td>stuff3
<td>stuff4</table>

Also, as can be seen in the guide above (hence why I commented here since it's a good example of the problem -and- is a guide relevant to the subject), some borders just don't even show up. In the first two examples for borders, the bottom border isn't showing. For the fourth example with four columns, the border between the third and fourth column isn't showing.

Speaking of the guide above, it also illustrates the first issue at the end. Note how both the "I'm huge" and "I'm tiny" tables are identical despite different coding. =(

Crackerhead22's picture

I think (not positive), that

I think (not positive), that when it comes to percentage with tables, that it needs to be CSS, otherwise it would be like your example.

I used CSS in my tables on my Archaeology guides, and using 50% actually worked. Like I said, not sure if that is the reason or not.

{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}

Jiyambi's picture

Hmmm, I'm seeing the borders

Hmmm, I'm seeing the borders on the tables in the examples. However, I see what you meen about the width. Unfortunately I don't really have a way (or knowledge of how) to muck about with the site display settings. I would suggest sending a PM or email to Snowflake, though I'm not sure how often she checks in.

kayeich's picture

Well, the width thing isn't

Well, the width thing isn't entirely a huge deal, like I said, there is a workaround for that (just bloats the code, but not entirely bothersome otherwise).

But that odd missing borders thing is bugging the heck out of me. I'll check to see if it pops up on my laptop I guess, since you said you didn't notice any missing borders, might just be some weird thing on my end somehow...

Jiyambi's picture

I'm on Firefox if that helps.

I'm on Firefox if that helps.

kayeich's picture

So am I actually. I just

So am I actually. I just checked my laptop though, and the borders show up fine there too, so I guess it's something isolated to this computer...

I'm pondering if it might be a resolution thing, since the resolution on my desktop is 1680x1050 while on the laptop it's 1024x768. That's about the only thing I can really think of being different between the two computers besides obvious hardware differences.

Crackerhead22's picture

Strange, I have two monitors,

Strange, I have two monitors, one with both screen resolutions you mention and I can see borders on both screens.

Jiyambi's picture

I'm on a 1280x1024. It does

I'm on a 1280x1024. It does sound like it could be a resolution issue.

Archerus's picture

Inside Table Borders

Can you set a different thickness to the borders separating interior cells? Like darken the line that separates Row 1 from Row 2, applied to the entire table.

Width of tables

Great guide which I found very useful.

Is it possible to set the size (width) of a table? Mine seems to have filled the whole page. Or is there a way to set the size of a column rather than letting it autosize?

dark_fanboy's picture

Yep! I'll add that in soon,

Yep! I'll add that in soon, but a quick example.

<table width="100%">

Don't be famous, be infamous

Don't be famous, be infamous

dark_fanboy's picture

What have I started!!!

Groovy, glad everyone likes it and please as always help me out and show me ways to improve upon things. I take all comments very seriously.

Don't be famous, be infamous

Don't be famous, be infamous

Jiyambi's picture

You inspired me to write a

You inspired me to write a guide about ToCs, so thanks! I think guides like this can really benefit the site, since it makes everyone's guides better Smiling

Jiyambi's picture

Some notes

<html> - you can make the tags without spaces. See this page for details on how to do this - basically it's some code for "special characters", so you can make the less than and greater than signs with that.

Also it's important to note that you CANNOT use HTML if you are using Mediawiki as an input format (which I learned with sadness). You probably want to mention this somewhere in your guide.

dark_fanboy's picture

Also it's important to note

Also it's important to note that you CANNOT use HTML if you are using Mediawiki as an input format (which I learned with sadness). You probably want to mention this somewhere in your guide.

This is confirmed true?

Don't be famous, be infamous

Don't be famous, be infamous

Jiyambi's picture

Think so

Well it sure as heck didn't work last time I tried it, but admittedly that was a few weeks ago.

dark_fanboy's picture

Groovy, I shall have to put

Groovy, I shall have to put this to the test here soon to confirm it myself. If you have an screenshots or errors that you can send my way feel free.

Don't be famous, be infamous

Don't be famous, be infamous

Jiyambi's picture

nvm

Edit: What I said in this comment not true, ignore it. The above comment was correct though Smiling

Jame's picture

Haha, with sadness Just

Haha, with sadness Eye

Just broke my heart right there!

Jiyambi's picture

I think the previous poster

I think the previous poster broke something in his comment, left a table tag un-closed or something - the page is all wonky now.

Edit: Nevermind, it appears to be fixed.

A few notes about CORRECT

A few notes about CORRECT HTML:
You should never use capitals. for example, not < HTML> or < Html> - < html>
Also the same with attributes - < table border="1">
When you have a tag without ending - for example < br>, you put / in the end.
< br/>

Jame's picture

That's awesome! Very nicely

That's awesome! Very nicely done.

I'll make sure to use this whenever the opportunity arises in one of my next guides Smiling

Skumball's picture

Very Sweet !

This is a great guide to help others create better quality guides, and also it's a great introduction for anyone into the world of HTML programing and CSS-based web editing.

A quick question to Jame on this subject...

Are we able to utilise a CSS within our guides, perhaps to format or design it? Personally I like to define everything's properties and then create and add the content, and much rather this to the way of formating content line-by-line.
Or are Style Sheets not possible within our guides.

No problems if not, I just think that they would add a greater scope for guide contributors to work with Smiling

Shikamaru's picture

As I can see, you are a

As I can see, you are a somewhat experienced user of HTML and CSS-based web editing.

As Jame said, it's not possible to add additional CSS content to buff the looks of your guide, I don't like it too, but whatever Sticking out tongue.

You can greatly enhance your guides with BBcode and (X)HTML too, you know! Smiling

Jame's picture

I don't think that's

I don't think that's possible :/

Skumball's picture

Hmm, HTML editing would be a

Hmm, HTML editing would be a good opton to have, it's probably abit more advanced though for the purposes of this site. Not everyone has had HTML experience lol Smiling

To Shikamaru... I'm a self-tought pro-web designer when I can be bothered to get off my backsaideand make abit of extra cash Smiling

Jame's picture

The option is already there.

The option is already there. Html can be used together with bbcode to write guides here, as long as you choose bbcode as input format Smiling

Skumball's picture

CSS

Hmm, I'll try making a guide using a style sheet, maybe even a guide about using stylesheets =P