html5中不再支持table的cellspacing和cellpadding屬性


如果你現在開始用html5的聲明來寫頁面時,你會發現在定義table的cellspacing和cellpadding時被提示該屬性已過時或者提示非法屬性。具體原因是在html5中table標簽的這兩個屬性已經被移除,需要定義邊框之類的時應該使用css的寫法。

具體實現如下:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Html5 Table Test</title>
    <style type="text/css">
        table{ border-collapse:collapse; border:solid 1px Black; }
        table td{ width:50px; height:20px;  border:solid 1px Black; padding:5px;}
    </style>
</head>
<body>
    <table>
        <tr>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
</body>
</html>

效果圖如下:

代碼的關鍵點在於border-collapse:collapse; 和 border:solid 1px Black;。對於padding的定義大家都比較熟悉了,這里主要講一下的是border-collapse中的collapse和separate值,定義為collapse時,他們的邊框會重疊在一起,定義為separate時單元格邊框之間會有間隙。不定義時默認為separate。 separate情況下的效果圖如下:

代碼定義很簡單,也是早版本瀏覽器就支持的東西,只是以前我們一些人習慣用cellspacing和cellpadding來定義,但這兩個屬性在html5中將要移除,所以需要改過來用css來定義而已。很簡單的東西,小記一下而已。

 

小記:在html5中,很多標簽元素的屬性都不復存在了。下面是html5中通用於每個標簽的核心屬性和語言屬性(有個別例外)。

class, contenteditable, contextmenu, dir, draggable, id, 
irrelevant, lang, ref, registrationmark, tabindex, template, title

轉載自:http://xxling.com/article/76.aspx


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 在html5中不支持 CSS中Cellpadding和 Cellspacing用法和定義 table中cesllspacing與cellpadding的區別 jsp中的警告:Attribute (cellpadding) is obsolete. Its use is discouraged in HTML5 documents. HTML中的table屬性 html5中不再支持的元素 html/html5中的download屬性 HTML5中meta屬性的使用詳解 html5中script的async屬性
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM
的cellpadding 和 cellspacing ; 2) 如何用css實現 cellpadding, cellspacing ; 3) tr , th 是 有 border, 沒有 padding 的. 表格(table)屬性cellspacing、cellpadding