2013-08-06 44 views
2

對不起,我知道類似的問題之前已經被問到過,但是他們中的任何建議都不適用於我的案例。我有一個表格(用於表格數據,而不是用於佈局),並且我不想在表格標題中看到邊框。據我所知,做到這一點的方法是在CSS中指定border-collaps: collapse;。然而,在我的情況下,邊界仍然可見。我搜索了這個網站,嘗試了這裏提出的各種解決方案 - border-spacing-0px, display-none - 但沒有任何工作。邊界仍然存在。在我的CSS代碼現在看起來像這樣:邊框崩潰不再工作

.tableStyle2 { 
    border-spacing: 0px; 
} 

.tableStyle2 th { 
    background-color: #1B7AE0; 
    border-color: #1B7AE0; 
    border-spacing: 0px; 
} 

.tableStyle2 tr { 
    display: none; 
} 

和相應的HTML代碼如下:

<table class = "tableStyle2" width = "100%"> 
<tr> 
<th> ... </th> 
<th> ... </th> 
<th> ... </th> 
<th> ... </th> 
<th> ... </th> 
</tr> 
</table> 

(該表的其餘部分尚未被寫入) 任何想法造成這種情況,以及如何隱藏表頭中單元格之間的邊界?

+0

發表更多你的實際代碼,甚至更好,提出一個小提琴。我試着用你展示的代碼演奏一個小提琴,我沒有看到任何邊框,所以必須有一些隱藏在細節中的東西。 – GreatBigBore

+0

問題的標題具有誤導性。 'border-collapse'屬性確實有效,但它不會執行錯誤地預期的操作(刪除邊框)。 –

回答

4

每個<td>都決定(並負責)自己的邊界。

.tableStyle2 { 
    border-spacing: 0px; 
    border-collapse:collapse; /* <--- add this so all the internal <td>s share adjacent borders */ 
    border:1px solid black; /* <--- so the outside of the <th> don't get missed */ 
} 

.tableStyle2 th { 
    background-color: #1B7AE0; 
    border-color: #1B7AE0; 
    border-spacing: 0px; /* <---- won't really need this if you have border-collapse = collapse */ 
    border-style:none; /* <--- add this for no borders in the <th>s */ 
} 

.tableStyle2 tr { 
    /* display: none; <--- you want to show the table */ 
} 
+0

謝謝!我試過這個,出於某種原因它不再顯示背景顏色,所以很難判斷是否有邊框。 確定他們的邊界,就像​​s?我應該在表頭中使用標籤而不是嗎?這可能與邊界崩潰無關嗎? – Mhoram

+0

我終於得到了消失的邊界!我把「邊界崩潰:崩潰」在tableStyle2和「border-style:none;」之下在tableStyle2下。換句話說,與您的建議並沒有根本的不同,而且,當我讓桌子看起來像我想要的樣子時,我仍然不確定爲什麼它在最初幾次都不起作用。不過謝謝你。 – Mhoram