In HTML5 websites centering and borders are done differently than in HTML 4.01. The HTML code is similar, but more css is used. The examples below show how a table is created, sized, centered and borders are added.
HTML5, as a general rule, uses less table code and more div "float" code (float:left;), especially in responsive designs. Tables are still part of the HTML5 standards and are useful for presenting information in columns and rows.
Before you start (current code)
Check your global css file to see that you do have the classes "center-div" and "td-center" near the top of the file. The following classes are included in Allwebco HTML5 and responsive web template css files to allow for centering and alignment.
HTML5 add a one cell centered table or div:
Use the following code for a 500 pixel wide centered table with centered contents (if your global css file includes the above classes):
Optionally, edit the "center-div" and "td-center" from center to left or right. If you do not require columns or rows, then using a div is the better choice in most cases.
One cell centered table with border:
Same as above with a border added:
Optionally, edit the "center-div" and "td-center" from center to left or right. If you do not require columns or rows, then using a div is the better choice in most cases.
Two cell centered table with outer border:
Same as above with a second cell and an outer border added:
Example: Chart table:
Copy and paste the code below to add the following 4 row, 3 column chart table. Works in both HTML5 and HTML 4.01 websites and web templates.
Note: In responsive websites and web templates, use caution when adding more columns so your table does not exceed around 300 pixels in width (text will wrap) and you maintain your webpage responsiveness.
Item Name
Item Details
Size
Name A
Det A
1
Name B
Det B
2
Name C
Det C
3
Step #1: Add to your HTML page:
Step #2A: Add to your CSS style file:
Can be added to the bottom of your global css file or in most any other spot. If you use this option do not use option #2B below.
Step #2B: Add to the head section of your HTML page: Optionally... Use this code ONLY if you do not have a global CSS file (style.css or similar name). You can view the source code of this page to see where the following code is added to the <head> section of your HTML page.