Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I replace <table border=1>' with `<table>` + css: `table{...}`?

table{border:1px solid #000;} doesn't seem to work without the border=1 statement. In the same way as changing <input width=30> into input{width:400px;}, I would like to use <table> and declare the border in css only. Is that possible?

Update my mistake was using

table{border-width:1px;}

instead of e.g.

table{border:1px solid #000;} 

--which works fine.

like image 565
ajo Avatar asked Mar 22 '11 16:03

ajo


2 Answers

Use this CSS:

table {
    border-collapse: collapse
}
td {
    border: 1px solid #000
}

Live Demo

border-collapse: collapse is important; without it you get doubled borders, like this.

like image 137
thirtydot Avatar answered Sep 28 '22 15:09

thirtydot


Absolutely - that is the preferred way. You might have to style td as well as tr.

like image 44
Daniel A. White Avatar answered Sep 28 '22 14:09

Daniel A. White