兩種單線邊框table

兩種實現table單線邊框的代碼:

<!doctype html>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>兩種單線邊框table</TITLE>
 
<STYLE type="text/css">
body{margin:0;padding:0;font-family:verdana,tahoma, arial, sans-serif; }
</STYLE>
</HEAD>
<BODY>
 
<div style='margin:20px 0 10px 50px;'>第一種:</div>

<table style='border-collapse:collapse;table-layout:fixed;width:300px;height:100px;box-sizing:border-box;margin-left:50px;'>
<tr>
<td style='width:100px;height:100px;box-sizing:border-box;border:#00f solid 1px;'>&nbsp;</td>
<td style='width:100px;height:100px;box-sizing:border-box;border:#00f solid 1px;'>&nbsp;</td>
<td style='width:100px;height:100px;box-sizing:border-box;border:#00f solid 1px;'>&nbsp;</td>
</tr>
</table>

<div style='margin:10px 0 10px 50px;font-size:14px;'>實現方式:<br/>table{border-collapse:collapse;} <br/> td{border:#00f solid 1px;}</div>


<div style='margin:50px 0 10px 50px;'>第二種:</div>

<table style='table-layout:fixed;width:300px;height:100px;margin-left:50px;box-sizing:border-box;border-top:1px solid #00f;border-left:1px solid #00f;border-spacing:0;'>
<tr>
<td style='width:100px;height:100px;border-right:#00f solid 1px;border-bottom:#00f solid 1px;box-sizing:border-box;'>&nbsp;</td>
<td style='width:100px;height:100px;border-right:#00f solid 1px;border-bottom:#00f solid 1px;box-sizing:border-box;'>&nbsp;</td>
<td style='width:100px;height:100px;border-right:#00f solid 1px;border-bottom:#00f solid 1px;box-sizing:border-box;'>&nbsp;</td>
</tr>
</table>

<div style='margin:10px 0 10px 50px;font-size:14px;'>實現方式:<br/>table{border-top:1px solid #00f;border-left:1px solid #00f;border-spacing:0;} <br/>td{border-right:#00f solid 1px;border-bottom:#00f solid 1px;}</div>


<div style='margin:50px 0 10px 50px;font-size:14px;width:600px;background-color:#000;color:#fff;'>從代碼看第一種方式更簡單。但我發現在某些特殊情況下,border-collapse:collapse;會導致兼容性問題,因此第二種方式比較健壯。</div>
</BODY>
</HTML>

在上面代碼中,兩種方法呈現效果是完全一樣的。但我發現第二種方式更爲健壯。(在一些更復雜代碼環境下border-collapse:collapse存在兼容性問題)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章