views:

1406

answers:

6
+6  Q: 

CSS Table Styling

+3  A: 

You better make a background image with just the corners, and not the borders. Apply a class to the top left, top right, bottom left and bottom right cell, to define that the corners-background image should be used.

And style the borders with css. Don't put them in the background image.

In your approach, you'll always gonna end up having the vertical lines in your background image not match the borders of the actual table cells.

postback
+2  A: 

Have you tried http://www.roundedcornr.com/?

DrG
+1  A: 
Eduardo Molteni
This makes sense to me. If I were using PHP, I'd put the above into two includable files - one that ends with the <td> for cell 5, and the other that begins with the </td> for cell 5. So you could include, insert content, include, and not clutter that page's code with so many nested table tags.
Nathan Long
How would you get the cell inner borders to the edge in this case? Do you mean that there would be as many 2,4,6 and 8 cells as there are cells in the table itself, and Cell 5 instead of holding an embedded table would hold the table data?
JeeBee
JeeBee: you are right, I'm correcting the answer.
Eduardo Molteni
+1  A: 

Do something like this...

XHTML: (sorry had to remove first '<' as it wouldn't let me post it normally, FIX THIS JEFF!)

table id="pricing" border="0" cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <th>Incoming calls</th>
      <th>National calls</th>
      <th>Calls to US &amp; Canada</th>
      <th>Calls to other Phones</th>
      <th>Calls to other Countries</th>
      <th>SMS text messages</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Select</td>
      <td>country</td>
      <td>from</td>
      <td>dropdown</td>
      <td>list</td>
      <td>above</td>
    </tr>
  </tbody>
</table>

CSS: #pricing { font-weight:bold; text-align:center }

  #pricing thead
  {
    background-image:url("images/pricing_top.gif");
    background-position:top;
    background-repeat:no-repeat;
    padding:10px 0 0 /* replace 10px with the height of pricing_top.gif */
  }

  #pricing th
  {
    background-image:url("images/pricing_header_bg.gif");
    background-repeat:repeat-y;
    border-bottom:1px solid #c3c2c2;
    width:100px /* replace 100px with the width of pricing_header_bg.gif */
  }

  #pricing tbody
  {
    background-image:url("images/pricing_bottom.gif");
    background-position:bottom;
    background-repeat:no-repeat;
    padding:0 0 10px /* replace 10px with the height of pricing_bottom.gif */
  }

  #pricing td
  {
    background-image:url("images/pricing_cell_bg.gif");
    background-repeat:repeat-y;
    width:100px /* replace 100px with the width of pricing_cell_bg.gif */
  }

Only drawback is that you have to create 4 images, but that shouldn't take too long. You'll also need to add a class to the final cell in each row if you want to add that drop shadow on the right and just change it's background-image and width property accordingly.

Andrew G. Johnson
You can do this with one image. One sprite containing the four corners: the top left corner in the bottom right corner of the sprite, the top right corner in the bottom left corner of the sprite, etc..Use CSS to position that background in each of the cells (with negative values for the position)
postback
No, not with the shadows and borders.
Andrew G. Johnson
+4  A: 

25 ways to do it.... http://www.cssjuice.com/25-rounded-corners-techniques-with-css/

Actually, there are too many ways to do it.

Arvind
+1  A: 

Playing off of your original idea, you could add a class to each corner cell effectively turning off their respective offending borders. You could then use a full-width background image in the <thead> and <tfoot> elements to account for the rounded corners.

The rest of the cells can have their borders turned on, and the lines will line up correctly.

The only remaining issue is accounting for that blasted drop shadow. That's a different exercise.

Zack Mulgrew