Forum Moderators: open
Many thanks for that, even though I've been doing webstuff
for about 3 years, I do find some of this a little
confusing, to make my question a little clearer, I've
repeated it in more detail below:
On some pages where I have more than one table, I have this
on the page:
<div align="center">
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
</center>
</div>
<div align="center">
<center>
<table>
<tr> <td> </td> </tr>
</table>
</center>
</div>
<div align="center">
<center>
<table>
<tr> <td> </td> </tr>
</table>
</center>
</div>
<div align="center">
Can I get away with using just this and not have any
problems?:
<div align="center">
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
</div>
The external css for the tables are here:
table {
width: 750px;
background-color: #ffffff;
bordercolor: #000000;
}
The tables should be aligned to the center and the text in them, if it's relevant to this, is to to the left.
Open to ideas.
<style type="text/css">
body {text-align:center;}
#all {width:100%;}
table {text-align:left; margin:0 auto; width:750px;}
</style>
<div id="all">
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
</div>
If you don't want a border (you set yours to white) I don't think you need to say so - there's no border by default until you add one.
The text-align:center (in the body) and :left (for the tables) is necessary for IE. In real browsers it's not needed.
This actually looks more slightly more complicated than yours, but it separates the style from the content, which is what everyone says we should be doing.
Do you actually need all those tables by the way? Is this something that <div>s or simply <p>s and good CSS couldn't handle?
<div id="all">
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
<table>
<tr> <td> </td> </tr>
</table>
</div>
If you don't want a border (you set yours to white) I don't think you need to say so - there's no border by default until you add one.
The text-align:center (in the body) and :left (for the tables) is necessary for IE. In real browsers it's not needed.
This actually looks more slightly more complicated than yours, but it separates the style from the content, which is what everyone says we should be doing.
Do you actually need all those tables by the way? Is this something that <div>s or simply <p>s and good CSS couldn't handle?
Many thanks for that, good tip on the white border, consider it deleted forthwith.
I boobed - some of the text in the tables is left-aligned and some is centered - what changes if any, would you make to your post please, in light of that?
It does need to be tables, for the moment.
I'm assuming that your top paragraph would go in the external css sheet?
body {text-align:center;}
#all {width:100%;}
table {text-align:left; margin:0 auto; width:750px;}
goes in your external stylesheet.
If the majority of your text is left-aligned, I'd leave this as it is but then for the parts which are centre-aligned, add a class in the appropriate place. So...
.centre {text-align:center} [in CSS]
and
<table class="centre">
<tr> <td> </td> </tr>
</table>
for a centre-aligned table.
Or
<table>
<tr class="centre"> <td> </td> </tr>
</table>
for a centre-aligned row, etc.
Of course, if you're using one-cell tables (are you?) this does the same thing.
By the way, sorry if it gets confusing when I mix up spellings of 'centre'. I know it has to be American for the CSS, but I like to spell it correctly where I can. (smiley goes here but I'm not sure how to do that on this forum - I see no buttons!)