How Do I Indent Text?

Discussion in 'HTML & Website Design' started by gobbly2100, Jun 22, 2007.

  1. #1
    I want to make it so my title in the tabe is slightly indented, how do I do that?

    
    <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="500" align="left" valign="middle">Title</td>
    </tr>
    <tr>
    <td align="left" valign="top">
    </p>Content
    </td>
    </tr>
    </table>
    
    Code (markup):
    I want the title to start about 10px from the left side if possible.
     
    gobbly2100, Jun 22, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Use cellpadding="10"

    Alternative, use CSS styles, e.g.:
    <td width="500" align="left" valign="middle" style="padding-left: 10px;">Title</td>
    Code (markup):
     
    krt, Jun 22, 2007 IP
  3. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you don't want that cell to be padded by 10px; on all 4 sides and only the left and right side, then you use the old hspace attribute , but be careful, because apparently, one day, browsers will no longer accept this tag.
     
    Arnold9000, Jun 22, 2007 IP
  4. danfinney

    danfinney Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <style type="text/css">
    <!--
    #gobbly {
    width:500px;
    border:0;
    margin:0;
    padding:0;
    text-align:left;
    }

    #gobbly th {
    text-indent:10px;
    vertical-align:middle;
    }

    #gobbly td {
    vertical-align:top;
    }

    -->
    </style>

    <table id="gobbly">
    <tr>
    <th>Title</th>
    </tr>
    <tr>
    <td>Content</td>
    </tr>
    </table>
     
    danfinney, Jun 22, 2007 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    What danfinney said so eloquently with clean code. We're talking appearance here... First off it's a header so use a TH instead of a TD, and get all that presentational nonsense out of the html and into CSS.

    I'd also add border-collapse:collapse so you get uniform behavior across all browsers.

    Yeah, going through it my HTML for that would be identical to danfinney's, though my css would read:

    * {
    margin:0;
    padding:0;
    }

    table {
    border-collapse:collapse;
    }

    #gobbly {
    width:500px;
    }

    #gobbly th {
    padding-left:10px;
    vertical-align:middle;
    }

    #gobbly td {
    text-align:left;
    vertical-align:top;
    }

    Mind you, using the universal selector to null all margins/padding and making all tables collapse their borders might require a rewrite of everything else you've done - but it is the easiest way I've found to write cross-browser code. The reason I used left-margin is I figure if the title wraps to two lines, you'd want the wrap indented too.
     
    deathshadow, Jun 23, 2007 IP
    danfinney likes this.
  6. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Why not just div it out or p it out and give it a margin of 10? That would take care of the multiple line problem
     
    Arnold9000, Jun 23, 2007 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    That's also a good point - I'm assuming he's using a table for one of the handful of legitimate reasons to do so...

    1) More than one column that need equal length.

    2) Need for vertical positioning of dynamic content.

    Uhm... Uhm... Yeah, one of those. There's only two good reasons... and the first of those is iffy.

    If it doesn't qualify as one of those, I'm with you. Drop the table and use a DIV, or even better, a header tag.

    <h2>Title></h2>
    <div class="content">
    <p>Test Content</p>
    <p>Test Content</p>
    <p>Test Content</p>
    <p>Test Content</p>
    </div>

    Only one column, not trying to vertically center or make content flush-bottom... NO REASON to use a table.
     
    deathshadow, Jun 23, 2007 IP
  8. danfinney

    danfinney Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Good call on the zero margins and the border collapse, deathshadow. I added some reps for you. (and giving the verbal explanation of what I said with just code)

    I start all of my css documents with the block below.

    /* --------- Normalize ---------- */

    * {
    margin: 0;
    padding: 0;
    }


    /* Normalize header sizes */
    h1, h2, h3, h4, h5, h6 {
    font-size: 100%;
    }

    /* Normalize list styles */
    ol, ul {
    list-style: none;
    }

    /* Normalize table borders */
    table {
    border-collapse: collapse;
    border-spacing: 0;
    }

    /* --------- End Normalize ---------- */
     
    danfinney, Jun 24, 2007 IP