怎样运用html中table实现td边框的结果(代码)
<!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边框的结果(代码)的具体内容,更多请关注百分百源码网其它相关文章!