table { empty-cells: hide;}
估計(jì)你從語(yǔ)義上已經(jīng)猜出它的作用了。它是為HTML table服務(wù)的。它會(huì)告訴瀏覽器,當(dāng)一個(gè)table單元格里沒(méi)有東西時(shí),就隱藏它。下面的演示里,你可以點(diǎn)擊里面按鈕,它會(huì)切換empty-cells的屬性值,看看table的顯示有什么變化。
HTML代碼
<table cellspacing="0" id="table"> <tr> <th>Fruits</th> <th>Vegetables</th> <th>Rocks</th> </tr> <tr> <td></td> <td>Celery</td> <td>Granite</td> </tr> <tr> <td>Orange</td> <td></td> <td>Flint</td> </tr></table> <button id="b" data-ec="hide">切換EMPTY-CELLS</button>
CSS代碼
body { text-align: center; padding-top: 20px; font-family: Arial, sans-serif;}table { border: solid 1px black; border-collapse: separate; border-spacing: 5px; width: 500px; margin: 0 auto; empty-cells: hide; background: lightblue;}th, td { text-align: center; border: solid 1px black; padding: 10px;}button { margin-top: 20px;}
js代碼
var b = document.getElementById('b'), t = document.getElementById('table');b.onclick = function () { if (this.getAttribute('data-ec') === 'hide') { t.style.emptyCells = 'show'; this.setAttribute('data-ec', 'show'); } else { t.style.emptyCells = 'hide'; this.setAttribute('data-ec', 'hide'); }};
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com