您的当前位置:首页正文

html表格删除部分边框,如何从HTML表格中完全删除边框

2024-11-20 来源:个人技术集锦

And in css:

table {border: none;}

EDIT:

As iGEL noted, this solution is officially deprecated (still works though), so if you are starting from scratch, you should go with the jnpcl's border-collapse solution.

I actually quite dislike this change so far (don't work with tables that often). It makes some tasks bit more complicated. E.g. when you want to include two different borders in same place (visually), while one being TOP for one row, and second being BOTTOM for other row. They will collapse (= only one of them will be shown). Then you have to study how is border's "priority" calculated and what border styles are "stronger" (double vs. solid etc.).

I did like this:

first row
second row

----------

.first {border-bottom:1px solid #EEE;}

.second {border-top:1px solid #CCC;}

Now, with border collapse, this won't work as there is always one border removed. I have to do it in some other way (there are more solutions ofc). One possibility is using CSS3 with box-shadow:

first row
second row
​​​

.tab {border-collapse:collapse;}

.tab .first {border-bottom:1px solid #EEE;}

.tab .second {border-top:1px solid #CCC;box-shadow: inset 0 1px 0 #CCC;}​

You could also use something like "groove|ridge|inset|outset" border style with just a single border. But for me, this is not optimal, because I can't control both colors.

Maybe there is some simple and nice solution for collapsing borders, but I haven't seen it yet and I honestly haven't spent much time on it. Maybe someone here will be able to show me/us ;)

Top