Search code examples
htmlcsscss-tables

Left and right margin on a table row


How can I set the left and right margin of a table row (or something similar to achieve the same result)? I tried border-collapse:separate; border-spacing:20px; but that removed the rows border bottom.

This is what I am trying to create:

http://i54.tinypic.com/eqce83.jpg


Solution

  • I do not think this is possible with tables.

    Here it is with divs and spans. I hope you like it:

    <html>
     <head>
      <style>
       div#outer {
        border: 10px solid black;
        width: 30em;
       }
       div#header {
        background-color: red;
        color: white;
        text-align: center;
       }
       div.row {
        border-bottom: 1px dashed red;
        margin: 10px 20px;
        clear: both;
       }
       span.left {
        float: left;
       }
       span.right {
        margin-left: 10em;
       }
      </style>
    </head>
     <body>
      <div id="outer">
      <div id="header">Some table head text</div>
       <div class="row">
        <span class="left">Col</span>
        <span class="right">Col</span>
       </div>
       <div class="row">
        <span class="left">Col</span>
        <span class="right">Col</span>
       </div>
       <div class="row">
        <span class="left">Col</span>
        <span class="right">Col</span>
       </div>
      </div>
     </body>
    </html>