Using CSS To Create Two Common HTML Border Effects

by Colin Cochrane 12/4/2007 5:01:00 PM

Seperating the style from the markup of a web document is generally a painless, if sometimes time-consuming, task.  In many cases however, the process can have some added speed-bumps; most notably when the original HTML is using an infamous table-based layout.  The two most common speedbumps when dealing with table-based layouts and styling are recreating the classic borderless table and keeping the default table border appearance.

The appearance of these two kinds of table are as follows 

Default Border

1 2
3 4

Borderless

1 2
3 4

The markup for these two tables looks like:
<!--Default Border -->
<table border="1">
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
<!-- Borderless -->
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>

If you want to get the same effects while losing the HTML attributes you can use the folllow CSS:

Default Border

table{border-spacing:0px;border:solid 1px #8D8D8D;width:130px;}
table td{
border:solid 1px #C0C0C0;
border-bottom:solid 1px #8D8D8D;
border-left:solid 1px #8D8D8D;
display:table-cell;
margin:0;
padding:0;}


Borderless

table{border:none;border-collapse:collapse;}
table td{padding:0;margin:0;}

Duplicating the default table border look requires extra rules in its style definition because the default border contains two shades so the border-color values must be set accordingly. 

That is the basic method to replicating HTML table effects with CSS that are usually created with HTML attributes.

Currently rated 4.3 by 37 people

  • Currently 4.297297/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

HTML | Web Development | Web Design | CSS

Comments

12/4/2007 4:55:49 PM

trackback

Trackback from DotNetKicks.com

Using CSS To Create Two Common HTML Border Effects

DotNetKicks.com

6/12/2008 5:07:21 AM

pingback

Pingback from michelsmoviecenter.com

Michele’s Movie Center » Using CSS To Create Two Common HTML Border Effects

michelsmoviecenter.com

6/15/2008 10:20:49 AM

fenerbahçe

css table properties and examples...
-- http://css-lessons.ucoz.com/table-examples-1.htm -- and -- http://css-lessons.ucoz.com/table-examples-2.htm

fenerbahçe us

6/15/2008 11:30:32 AM

Colin Cochrane

Thanks fenerbahçe. Good reference pages!

Colin Cochrane

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/6/2008 4:13:33 AM

Powered by BlogEngine.NET 1.3.1.0

All Content and Intellectual Property is under Copyright Protection | Colin Cochrane ©2007

About the author

Colin Cochrane

Colin Cochrane

SEO and ASP.NET Developer.

Recent comments

Recent posts

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. © Copyright Colin Cochrane 2008

Sign in