Forum Moderators: not2easy
<table>
<tr>
<td>Column1 Heading Name: </td>
<td>column1data</td>
</tr>
<tr>
<td>Column2 Heading Name: </td>
<td>column2data</td>
</tr>
<table>
OK, I've hard-coded two rows read from a table; typically I would run a server side loop to build the structure. I want the columns to remain aligned. Any insight or examples would be deeply appreciated.
Create a DIV that's the width and style you want as the overall table.. borders, background color, whatever you want.
Now create a DIV with a class of 'row', associate this CSS with it:
div.row { clear: both; padding-top: 10px; } So now you have:
<div class="table">
<div class="row">
</div>
</div> Let's say you want two columns in your table. Let's called them a and b. Put them in spans like this.
<span class="a">Left hand side</span><span class="b">Right hand side</span> Now associate this CSS:
div.row span.a { float: left; width: 100px; text-align: right; }
div.row span.b { float: right; width: 335px; text-align: left; } And so your main code now looks like this:
<div class="table">
<div class="row">
<span class="a">Left</span><span class="b">Right</span>
</div>
<div class="row">
<span class="a">Left</span><span class="b">Right</span>
</div>
<div class="row">
<span class="a">Left</span><span class="b">Right</span>
</div>
</div> And so on.. all properly indented when you do it, of course :-)
This method is taken (stolen?) from an article over at AListApart, although I am weary of linking to things on here as it tends to be frowned upon. You can sticky me for the URL to the page which details this process, however. :)
Of course, the poster above is right. This is probably an opportunity where you should use a TABLE, but this is not true in every case. Sometimes you will need to use CSS/DIVs to remain standards compliant.
wackybrit, what standards compliance are you referring to here?
<< Sometimes you will need to use CSS/DIVs to remain
<< standards compliant.