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

て烟熏妆下的殇ゞ 提交于 2019-12-06 03:53:15

问题


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.


回答1:


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.




回答2:


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




回答3:


Try this in CSS

 table
    {
    border:1px solid black;
    }

then you can use it in HTML

<table>
....
</table>



回答4:


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

I suggest doing:

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




回答5:


Your style should be:

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

See a working example here.




回答6:


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

td { border: 1px solid #000000; }

you will need to also add:

th { border: 1px solid #000000; }

Regards,



来源:https://stackoverflow.com/questions/5394785/can-i-replace-table-border-1-with-table-css-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!