Is it possible to replace <table border = 1> 'with `<table>` + css: `table {...}`?

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

Update my mistake was to use

 table{border-width:1px;} 

instead of for example

 table{border:1px solid #000;} 

- works great.

+4
source share
6 answers

Use this CSS:

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

Live demo

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

+10
source

Absolutely is the preferred way. You may need td style as well as tr .

+3
source

Try this in CSS

  table { border:1px solid black; } 

then you can use it in HTML

 <table> .... </table> 
+1
source

yes, but if you use table , it will affect ALL tables in your html.

I suggest doing:

<table class="myTable"> and then .myTable { /*css*/ }

0
source

Your style should be:

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

See a working example here .

0
source

If you use <th> for headers with the code below, you will not get borders around our headers:

 td { border: 1px solid #000000; } 

you also need to add:

 th { border: 1px solid #000000; } 

Hello,

0
source

Source: https://habr.com/ru/post/1344805/


All Articles