 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Mori
Joined: 20 Jul 2009 Posts: 21
|
Posted: Mon Sep 21, 2009 5:07 am How To Center A Table |
|
|
|
Hi everyone,
On the following reference, HTML learners are advised not to use table align attribute and use styles instead. But I don't know how to do it:
http://www.w3schools.com/TAGS/tag_table.asp
Any help is appreciated.
Regards
Mori |
|
sticks464

Joined: 31 Dec 2006 Posts: 2627
|
Posted: Mon Sep 21, 2009 5:35 am |
|
|
|
You can use an inline stylesheet for starters until you get the hang of it.
In the page head section immediately following the title tag add this opening and closing tag.
| Code: |
<style type="text/css">
</style> |
In the html markup add an id to the main table, can be any name to identify this table (cannot start with a number or contain spaces)
| Code: |
| <table id="anyname" cellspacing="0"> |
Now to style the table and get it aligned use these attributes inside the style tags created in the head section.
| Code: |
#anyname {
width: 750px;
margin: 0 auto;
border: 0;
padding:0;
} |
width = width of table
margin = 0px at the top and bottom, auto = equal margins left and right consisting of the remaining space available of the viewport after the width of the table is subtracted. (Basically means it is centered in the screen).
border = none
padding = none (same as cellpadding)
margin: 0 auto will always center an element unless the element width is set to 100%. |
|
tiepich
Joined: 15 Oct 2009 Posts: 3
|
Posted: Fri Oct 16, 2009 8:47 am Re: How To Center A Table |
|
|
|
| Mori wrote: |
Hi everyone,
On the following reference, HTML learners are advised not to use table align attribute and use styles instead. But I don't know how to do it:
http://www.w3schools.com/TAGS/tag_table.asp
Any help is appreciated.
Regards
Mori |
or you can add a style directly into table tag, if you do not want to have external styles, for example:
| Code: |
<table style="background-image:url(images/image.jpg); background-repeat: no-repeat; background-position:top center;"> |
|
|
Mori
Joined: 20 Jul 2009 Posts: 21
|
Posted: Fri Oct 16, 2009 9:02 am |
|
|
|
Thanks for the reply!
I tried your code, but it didn't center my table. Would you please give me the table complete code?
Thanks again! |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|