27
Aug
08

How to put a border around single cells in HTML Tables

I’m currently making a website and stumbled across the problem with tables, cells and borders. The solution is to use CSS.

I found no ‘attractive’ way of using HTML tables, so decided to do the following:

The easiest way to do this is to go to the top of your document (code view, if your using a program) and add this anywhere in your style set (under style type=”text/css”…)

Now what you are going to do is create a ‘type’ of table cell. You give this ‘type’ of table certain rules, such as having a border. First you will need to name the table, I called mine ‘BlackBorder’.

This is the code you should type in:

.BlackBorder {
border: 2px solid #000000;
}

I only needed a 2px thick border, so you can adjust that to what you want. You could also add other ‘rules’ or properties to your table, if you know how to add them.

Now go back down to where the actual table cell you want the border around is. Now you are going to define a class for this table (class means one of the named ‘types’ of table).

At the table’s td or table tag, type class=”BlackBorder”, as below.

<td width=”306″ rowspan=”2″ class=”BlackBorder”

If your using Dreamweaver this will be much easier, as you can just select which cell you want and give it the BlackBorder ‘class’ in the attributes window.


2 Responses to “How to put a border around single cells in HTML Tables”


  1. November 2, 2008 at 9:39 am

    hi!!! how to apply curve in four sides of the border

  2. 2 Dave
    November 2, 2008 at 9:43 pm

    I think you would have to make it in illustrator or something and put it as a backround image (inside the cells you want with that border!

    Worth checking with someone else too though!


Leave a Reply