您好,欢迎访问一九零五行业门户网

如何使用html中table实现td边框的效果(代码)

今天给大家分享一篇关于htmltable各种边框效果实现的文章,内容主要介绍了在html利用table设置边框的各种操作,有需要的朋友可以参考一下。
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/tr/rec-html40/loose.dtd"> <html> <head> <title>table边框测试</title> </head> <body> <p style="width:100%;height:100%;"> <table border="1" bordercolor="#ff9966" > <tr> <td width="102" style="border-right-style:none">隐藏右边框</td> <td width="119" style="border-left-style:none">隐藏左边框</td> </tr> <tr> <td style="border-top-style:none">隐藏上边框</td> <td style="border-bottom-style:none">隐藏下边框</td> </tr> </table> <table> <tr> <td style="border-right:#cccccc solid 1px;">显示右边框</td> <td style="border-left:#cccccc solid 1px;">显示左边框</td> <td style="border-top:#cccccc solid 1px;">显示上边框</td> <td style="border-bottom:#cccccc solid 1px;">显示下边框</td> </tr> </table> <table> <tr> <td style="border-right : thin dashed blue;">右边框显示细虚线</td> <td style="border-bottom: thick dashed yellow;">下边框显示粗虚线</td> <td style="border-top: double green;">上边框显示两条线</td> <td style="border-left: dotted red;">左边框显示点</td> </tr> </table> </p> </body> </html>
效果如下:
.表格中边框的显示
只显示上边框 <table frame=above>
只显示下边框 <table frame=below>
只显示左、右边框 <table frame=vsides>
只显示上、下边框 <table frame=hsides>
只显示左边框 <table frame=lhs>
只显示右边框 <table frame=rhs>
不显示任何边框 <table frame=void>
.表格的分隔线可以隐藏
<table border rules=cols cellspacing=0 align=left> 可以隐藏横向的分隔线
<table border rules=rows cellspacing=0 align=right>可以隐藏纵向的分隔线
<table border rules=none cellspacing=0 align=center>可以隐藏横向和纵向的分隔线
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head><title> new document </title><meta name="generator" content="editplus"><meta name="author" content=""><meta name="keywords" content=""><meta name="description" content=""></head><body><table cellspacing=0 cellpadding=0 width="90%" align=right border=1 rules=rows frame=hsides style="border-collapse:collapse ; " bordercolor="#000000" ><tr><td >sadad</td><td >sad</td><td>dsa</td><td>asd</td></tr><tr><td >ads</td><td>asd</td><td>ads</td><td>asds</td></tr></table></body></html>
table width=1 就已经把宽度设置为 1 了
我们面临的问题是这样的,每一个 td 边线都是 1px,table 边线也是 1px。那么当两个td相邻的时候,因为每个 td 边线都是1,所以靠进的时候边线的“宽度和”就是 1+1=2。当 td 和 table 相邻时,同样。
collapse :  相邻边被合并
相邻边被合并!以前我说的 1+1=2 就是因为 td 和td之间,td 和table 之间相邻边的问题。默认时相邻边没有合并,所以就是 1+1=2。现在我们使用 border-collapse:collapse把我们合并了,所以宽度还是 1px。也就是出现细线边框了
设置table的细边框通常有这么几种方式:
1、设置边框的border=0 、cellspacing=1,设置table的背景色为所要的边框色,再设置所有的td背景色为白色,这样细边框就显露出来了。这个方法有些邪气,看似不太正宗,但是也能达到效果,条条大路通罗马嘛!
再来看看第二种方法:
2、设置border=0 ,再通过css,给table加上1px的border-top,border-left,然后再设置所有的td的border-right,border-bottom,这样也能达到所要的效果。可见css很是强大啊。
今天在实践过程中发现,以上两种方式生成的html在word中打开则发生问题,不能达到预期效果。怎么办呢!?
下面介绍一种更为简便有效的方法:
3、设置table的css为{border-collapse:collapse;border:none;},再设置td的css为{border:solid #000 1px;},大功告成!而且word也能认出这种设置。
第三种方法最好,我也是在导出word时,很多css失效的情况下,找到了这个解决办法!
相关推荐:
html+css和div如何实现排版布局
html用表格布局来实现用户注册表单实例
以上就是如何使用html中table实现td边框的效果(代码)的详细内容。
其它类似信息

推荐信息