我有HTML看起來像這樣:我如何編碼cellspacing = 0,因此它是有效的HTML5?
<table class="table" style="clear: both;" width="100%" cellspacing="0">
我的IDE告訴我,寬度和CELLSPACING不是有效的HTML5。
有沒有一種方法可以編碼,使其有效?
我有HTML看起來像這樣:我如何編碼cellspacing = 0,因此它是有效的HTML5?
<table class="table" style="clear: both;" width="100%" cellspacing="0">
我的IDE告訴我,寬度和CELLSPACING不是有效的HTML5。
有沒有一種方法可以編碼,使其有效?
那麼,使用border-collapse: collapse;
CSS規則(其效果相同:表格單元格之間沒有空格)。請注意,這可能不適用於IE 5或6之類的舊版瀏覽器,因此如果您需要支持它們,那麼您運氣不佳。
<table class="table" style="clear: both; border-collapse: collapse; width: 100%;">
的width
和cellspacing
屬性確實貶值作爲HTML5的。處理這個問題的正確方法是使用CSS。
對於CELLSPACING,請參閱這樣的回答:In HTML5, with respect to tables, what replaces cellpadding, cellspacing, valign, and align?
我從上面的鏈接答案中摘錄的代碼(歸功於@Drudge):
這是CELLSPACING =「5爲例「
.table {
border-collapse:separate;
border-spacing: 5px;
}
這是CELLSPACING =一個例子」 0"
.table {
border-collapse:collapse;
border-spacing: 0;
}
要解決你的width
屬性無效,只需使用CSS width
屬性:
.table {
width:100%;
}