7 replies [Last post]
Gary
Offline
newbie
Last seen: 15 years 50 weeks ago
Timezone: GMT-5
Joined: 2003-08-04
Posts: 10
Points: 0

How can I add a border to a <table>? (Without using <table border="1">, because this doesn't conform with the XHTML 1.1 strict standard.)

DJSdotcom
Offline
Enthusiast
Rochester, NY / Chicago, IL
Last seen: 16 years 17 weeks ago
Rochester, NY / Chicago, IL
Joined: 2003-03-23
Posts: 95
Points: 0

How to add a border to a &lt;table&gt;?

I assume this will work:

table {
    border: 1px solid black; }

Or am I overlooking something?

-Mike

</twocents>

Gary
Offline
newbie
Last seen: 15 years 50 weeks ago
Timezone: GMT-5
Joined: 2003-08-04
Posts: 10
Points: 0

How to add a border to a &lt;table&gt;?

Thanks, works.

Gary
Offline
newbie
Last seen: 15 years 50 weeks ago
Timezone: GMT-5
Joined: 2003-08-04
Posts: 10
Points: 0

How to add a border to a &lt;table&gt;?

DJSdotcom wrote:
I assume this will work:

table {
    border: 1px solid black; }

Or am I overlooking something?

-Mike

This isn't like border="1" though; it only shows the outer border, but border="1" shows the borders for ALL cells. How can I duplicate this?

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 18 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

table borders

That only gives the border to the outside of the table.
you need to add the border to the td 's as well

table, table td {
    border: 1px solid black; } 
should do the trick

Gary
Offline
newbie
Last seen: 15 years 50 weeks ago
Timezone: GMT-5
Joined: 2003-08-04
Posts: 10
Points: 0

Re: table borders

Tony wrote:
That only gives the border to the outside of the table.
you need to add the border to the td 's as well
table, table td {
    border: 1px solid black; } 
should do the trick

But, this code will have ALL tables have a border. I don't want that, only certain tables.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 18 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

How to add a border to a &lt;table&gt;?

Give the table a class or id then just assign the border to that class or id.
<table class="hasborder">
.hasborder, .hasborder td{border: 1px solid black; }
Hope that helps

Gary
Offline
newbie
Last seen: 15 years 50 weeks ago
Timezone: GMT-5
Joined: 2003-08-04
Posts: 10
Points: 0

How to add a border to a &lt;table&gt;?

Tony wrote:
Give the table a class or id then just assign the border to that class or id.
<table class="hasborder">
.hasborder, .hasborder td{border: 1px solid black; }
Hope that helps

Thanks for the help.