• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1684
  • Last Modified:

CSS Table Border, Easy Points

I have a page setup using tables (not frames).  Inside the "body" cell, I have another table.  I want the interior table to have a 1 pixel black border around each cell and around the outside of the table.  I know this can be done via CSS.  What I have right now is rather cumbersome, and I'd like a cleaner solution.

<table style="border-collapse: collapse; border:1px solid #000000;">
  <tr>
    <td style="border:1px solid #000000;"></td>
    <td style="border:1px solid #000000;"></td>
    ....
</table>

The ideal solution would be that I could just write:
  <table class=onepixel>
    <tr>
      <td></td>
      ...
  </table
and be done with it.

I can't just put
  TABLE   { border-collapse: collapse;}
  TD {border:1px solid #000000;}
in my style sheet because that would affect the outer table (which needs to be competely transparent).

Thanks in advance!
0
dgooding
Asked:
dgooding
  • 5
  • 5
  • 2
  • +1
2 Solutions
 
seanpowellCommented:
I don't follow you - you do want an outside border or you don't ?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>

<style type="text/css">

table { border:1px solid #000;}
td    { border:1px solid #000;}

</style>

</head>
<body>

<table>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>
0
 
stu215Commented:
I think this is what your looking for ....


<style type="text/css">

table { border:1px solid #000000;border-collapse: collapse; border-spacing:0;}
td    { border:1px solid #000000;}

</style>

~Stu :-)
0
 
dgoodingAuthor Commented:
Well.  Yes and no.  Yes I want an outside border on the interior table, but not exterior table.  

Here's the basic layout of the two tables (they're more complicated than this, but just so you get the idea).

<table>         <------ outside table  (no borders whatsoever)
  <tr>
    <td>
      menu
    </td>
  </tr>
  <tr>
    <td>
      body
          <table>         <------ inside table   (one pixel collapsed borders inside and out)
            <tr>
              <td>
                data
              </td>
            </tr>
          </table>
      /body
    </td>
  </tr>
</table>

So just doing the
  <style type="text/css">
    table { border:1px solid #000;}
    td    { border:1px solid #000;}
  </style>
will affect the outsite table (not ok).  Just the inside table needs borders.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
stu215Commented:
-- Put that after the </head> tag but before the <body> tag

~Stu :-)
0
 
seanpowellCommented:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>

<style type="text/css">

.border { border:1px solid #000;}

</style>

</head>
<body>

<table>
  <tr>
    <td>menu</td>
  </tr>
  <tr>
    <td>
      body
          <table class="border">
            <tr>
              <td class="border">data </td>
            </tr>
          </table>
      </body
    </td>
  </tr>
</table>


</body>
</html>
0
 
dgoodingAuthor Commented:
seanpowell is basically correct...  :)  two things...  

is there a way to do it without also having to define the class in the <td>?  

can you define an object to have two class types (that deal with different attributes)?  
0
 
seanpowellCommented:
>>is there a way to do it without also having to define the class in the <td>?

Yes, see below.

>>can you define an object to have two class types (that deal with different attributes)?  

Yes, see below again.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>

<style type="text/css">

table td table, table td table td { border:1px solid #000;}

table td table td { background-color:#ccc;}

</style>

</head>
<body>

<table class="noborder">
  <tr>
    <td>menu</td>
  </tr>
  <tr>
    <td>
      body
          <table>
            <tr>
              <td class="border">data </td>
            </tr>
          </table>
      </body
    </td>
  </tr>
</table>


</body>
</html>
0
 
seanpowellCommented:
table td table, table td table td { border:1px solid #000;}

This means, look for a table within a table and give it a border - AND - look for a td within a table within a table and give it a border :-)
0
 
monolith_888Commented:
You're looking for this:
TD within a TABLE within a TABLE.
This will affect all TD's inside a double nested TABLE structure, without having to define classes.

<style>
table table td {border:1px solid #000;}
</style>

For that add-on, yes you can have two class types in an object, just seperate the class names with a space:
<style>
.style1 {font-family:tahoma;}
.style2 {font-weight:bold;}
</style>
<span class="style1 style2">blah</span>

Cheers!
Blake
0
 
dgoodingAuthor Commented:
That's cool.  I've never seen that before.  
I suppose the class="border" and class="noborder" are artifacts of previous attempts?  I removed them and it worked fine (since they aren't defined in the style)....

0
 
dgoodingAuthor Commented:
Increasing points so that both monolith and seanpowell can have a decent amount.  Both of you showed me things I've never seen before.  Nicely done.
0
 
monolith_888Commented:
Glad to help, and thanks!  seanpowell must've been typing when I was typing :-p
0
 
dgoodingAuthor Commented:
Yup!   :)

Had to give seanpowell a few more points, cause his was posted first, and was correct.  But I just couldn't let a good answer go to waste !!
0
 
seanpowellCommented:
I wondered what that sound was :-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now