Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an outline border on a colgroup?

I have a table with 17 columns, divided into 3 column groups. I can set the background colour using CSS, which suggests that my CSS selectors are fine. I can't, however, set a border around the outside of each colgroup.

First I tried this CSS:

colgroup.inbound, colgroup.outbound {
    background-color: #eeeeee;
    border: 1px solid red;
}

And defined column groups this way:

<colgroup span="2"></colgroup>
<colgroup span="12" class="inbound"></colgroup>
<colgroup span="3" class="outbound"></colgroup>       

Next I tried this CSS:

col.inbound, col.outbound {
    background-color: #eeeeee;
    border: 1px solid red;
}

And defined the groups this way:

<colgroup
    <col span="2">
    <col span="12" class="inbound">
    <col span="3" class="outbound">            
</colgroup>

In both cases my background colour takes effect, but not my border. The only border I can see is a thin white line between all cells (not around the group as a whole).

I am aware of the table rules attribute however I would prefer not to use this. I think CSS will give me more flexibility, if I can work out how to use it!

like image 642
DatsunBing Avatar asked Feb 26 '13 01:02

DatsunBing


People also ask

How do I add a border to a table body?

Anyway, we recommend using the CSS border property for adding a border to your tables. To add a border to your table, you need to define the <style> of your table. Remember to add borders also for <th> and <td> tags to have a complete table.

How do I add a border to a row in a table?

If you want to add a border only to the bottom of the table row, you can apply the CSS border-bottom property to <td> elements that are placed within a <tr> tag.


1 Answers

In order to make borders working when using tables you should set the following rule to the table

table.collapsed{
  border-collapse:collapse;
}

The you will get your border as you pretend

enter image description here

col.inbound, col.outbound {
    background-color: #eeeeee;
    border: 1px solid red;
}

A simple example in this JsBin

Option A border for the whole group instead of for each of the columns

enter image description here

Then you should rule the colgroup instead of the cols as so..

colgroup.inbound  {
  border: 1px solid #ff0000;
}

remember allways to use the border-collapse! This can be seen at this JsBin

like image 56
Fico Avatar answered Oct 11 '22 23:10

Fico