Question HTML - tables

Discussion in 'HTML' started by Rom, Jan 14, 2006.

  1. Rom

    Rom Guest

    Hello everybody,

    here's my problem :
    I have a table with 3 rows and 2 columns. Is it possible to right-align
    the text in the left column without writing thrice "<td align="right">" ?

    Here's the code :

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head><title></title></head>
    <body>
    <table border="1" width="20%">
    <tr>
    <td colspan="2" align="center">Data</td>
    </tr>

    <tr>
    <td>A</td><td align="right">1</td>
    </tr>

    <tr>
    <td>B</td><td align="right">2</td>
    </tr>

    <tr>
    <td>C</td><td align="right">3</td>
    </tr>

    </table>
    </body>
    </html>
    Rom, Jan 14, 2006
    #1
    1. Advertising

  2. Rom wrote:
    > Hello everybody,
    >
    > here's my problem :
    > I have a table with 3 rows and 2 columns. Is it possible to right-align
    > the text in the left column without writing thrice "<td align="right">" ?
    >
    > Here's the code :
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <html>
    > <head><title></title></head>
    > <body>
    > <table border="1" width="20%">
    > <tr>
    > <td colspan="2" align="center">Data</td>
    > </tr>
    >
    > <tr>
    > <td>A</td><td align="right">1</td>
    > </tr>
    >
    > <tr>
    > <td>B</td><td align="right">2</td>
    > </tr>
    >
    > <tr>
    > <td>C</td><td align="right">3</td>
    > </tr>
    >
    > </table>
    > </body>
    > </html>



    Since your "Data" and "A", "B" & "C" cell appear to be heading not data
    cells, style them differently, (look up TH element).

    In your stylesheet:

    TABLE { width: 20%, border: 1px solid black; }
    TH, TD { border: 1px solid black; }
    TD { text-align: right; }


    Your HTML:

    <table>
    <tr><th colspan="2">Date</th></tr>
    <tr><th>A</th><td>1</td></tr>
    <tr><th>B</th><td>2</td></tr>
    <tr><th>C</th><td>3</td></tr>
    </table>

    If you want more that one type of styling for your data cell then create
    classes like:

    ..totals, .bucks { text-align: right: padding-right: .5em; }
    ..totals { font-weight: bold; }


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Jan 14, 2006
    #2
    1. Advertising

  3. Rom

    Rom Guest

    Jonathan N. Little a écrit :
    > Rom wrote:
    >> Hello everybody,
    >>
    >> here's my problem :
    >> I have a table with 3 rows and 2 columns. Is it possible to
    >> right-align the text in the left column without writing thrice "<td
    >> align="right">" ?
    >>
    >> Here's the code :
    >>
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    >> "http://www.w3.org/TR/html4/strict.dtd">
    >> <html>
    >> <head><title></title></head>
    >> <body>
    >> <table border="1" width="20%">
    >> <tr>
    >> <td colspan="2" align="center">Data</td>
    >> </tr>
    >>
    >> <tr>
    >> <td>A</td><td align="right">1</td>
    >> </tr>
    >>
    >> <tr>
    >> <td>B</td><td align="right">2</td>
    >> </tr>
    >>
    >> <tr>
    >> <td>C</td><td align="right">3</td>
    >> </tr>
    >>
    >> </table>
    >> </body>
    >> </html>

    >
    >
    > Since your "Data" and "A", "B" & "C" cell appear to be heading not data
    > cells, style them differently, (look up TH element).
    >
    > In your stylesheet:
    >
    > TABLE { width: 20%, border: 1px solid black; }
    > TH, TD { border: 1px solid black; }
    > TD { text-align: right; }
    >
    >
    > Your HTML:
    >
    > <table>
    > <tr><th colspan="2">Date</th></tr>
    > <tr><th>A</th><td>1</td></tr>
    > <tr><th>B</th><td>2</td></tr>
    > <tr><th>C</th><td>3</td></tr>
    > </table>
    >
    > If you want more that one type of styling for your data cell then create
    > classes like:
    >
    > .totals, .bucks { text-align: right: padding-right: .5em; }
    > .totals { font-weight: bold; }
    >
    >

    Thanks. that's precisely what I was looking for ;)
    See you.
    Rom, Jan 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Royal Hale

    Reading HTML Tables in .Net

    Royal Hale, Feb 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    431
    Royal Hale
    Feb 24, 2004
  2. Peter Bassett
    Replies:
    3
    Views:
    917
    Augustus
    Aug 15, 2003
  3. Otuatail

    Tables within tables

    Otuatail, Jul 31, 2004, in forum: HTML
    Replies:
    7
    Views:
    486
  4. Replies:
    3
    Views:
    2,324
  5. Chris Brat
    Replies:
    5
    Views:
    689
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
Loading...

Share This Page