Solved

CSS Table Border, Easy Points

Posted on 2004-04-05
14
1,667 Views
Last Modified: 2012-05-04
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
Comment
Question by:dgooding
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
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
 
LVL 10

Expert Comment

by:stu215
Comment Utility
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
 
LVL 2

Author Comment

by:dgooding
Comment Utility
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
 
LVL 10

Expert Comment

by:stu215
Comment Utility
-- Put that after the </head> tag but before the <body> tag

~Stu :-)
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
<!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
 
LVL 2

Author Comment

by:dgooding
Comment Utility
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
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
>>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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 31

Accepted Solution

by:
seanpowell earned 125 total points
Comment Utility
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
 
LVL 4

Assisted Solution

by:monolith_888
monolith_888 earned 75 total points
Comment Utility
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
 
LVL 2

Author Comment

by:dgooding
Comment Utility
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
 
LVL 2

Author Comment

by:dgooding
Comment Utility
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
 
LVL 4

Expert Comment

by:monolith_888
Comment Utility
Glad to help, and thanks!  seanpowell must've been typing when I was typing :-p
0
 
LVL 2

Author Comment

by:dgooding
Comment Utility
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
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
I wondered what that sound was :-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now