Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a rounded border on my table and border-collapse: collapse? [duplicate]

Tags:

css

I have the following:

<TABLE style="border-radius: 5px; border: 1px solid #999; xborder-collapse: collapse;">
  <THEAD>
    <TR style="background-color: red;">
      <TH>Weekday</TH>
      <TH>Date</TH>
      <TH>Manager</TH>
      <TH>Qty</TH>
    </TR>
  </THEAD>
  <TBODY>
    <TR>
      <TD>Mon</TD>
      <TD>09/11</TD>
      <TD>Kelsey</TD>
      <TD>639</TD>
    </TR>
    <TR>
      <TD>Tue</TD>
      <TD>09/12</TD>
      <TD>Lindsey</TD>
      <TD>596</TD>
    </TR>
    <TR>
      <TD>Sun</TD>
      <TD>09/17</TD>
      <TD>Susan</TD>
      <TD>272</TD>
    </TR>
  </TBODY>
</TABLE>

Example

I would like to have rounded borders, no space between cells also have the top header area of my table a different color. But it doesn't seem to work.

I created this fiddle. When I comment out border-collapse I get the rounded edges but spaces between cells. When it's in I get no border radius and no space between cells.

Update:

Here seems to be the perfect solution: Fiddle

like image 882
Samantha J T Star Avatar asked Jan 17 '12 04:01

Samantha J T Star


People also ask

How do I make my table border rounded in HTML?

Use the CSS border-radius property to add rounded corners to the table cells.

What is the difference between border-collapse collapse and border-collapse separate?

(See Snippet below to confirm). The border-collapse CSS property determines whether a table's borders are separated or collapsed. In the separated model, adjacent cells each have their own distinct borders. In the collapsed model, adjacent table cells share borders.

How do you set a border-radius to a table in CSS?

CSS Syntaxborder-radius: 1-4 length|% / 1-4 length|%|initial|inherit; Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. If bottom-left is omitted it is the same as top-right. If bottom-right is omitted it is the same as top-left.


2 Answers

Adding border-spacing:0 instead of border-collapse:collapse on your table tag fixes it:

jsFiddle Demo

like image 171
SpoonNZ Avatar answered Oct 05 '22 10:10

SpoonNZ


Here's an example using a wrapper div :

<div style="display: table;
            padding: 2px;
            border-radius: 5px;
            border: 1px solid #999;">
  <TABLE style="border-collapse: collapse;">
    <THEAD>
      <TR style="background-color: red;">
        <TH>Weekday</TH>
        <TH>Date</TH>
        <TH>Manager</TH>
        <TH>Qty</TH>
      </TR>
    </THEAD>
    <TBODY>
      <TR>
        <TD>Mon</TD>
        <TD>09/11</TD>
        <TD>Kelsey</TD>
        <TD>639</TD>
      </TR>
      <TR>
        <TD>Tue</TD>
        <TD>09/12</TD>
        <TD>Lindsey</TD>
        <TD>596</TD>
      </TR>
      <TR>
        <TD>Sun</TD>
        <TD>09/17</TD>
        <TD>Susan</TD>
        <TD>272</TD>
      </TR>
    </TBODY>
  </TABLE>
</div>

You can see it working here: jsFiddle

Note: display:table; is not supported in IE7 and earlier. IE8 requires a: !DOCTYPE in the document. All modern browsers (including IE9) support it though, so it shouldn't be a problem.

like image 20
vdbuilder Avatar answered Oct 05 '22 09:10

vdbuilder