2015-12-14 37 views
0

表頭對準我與的tablesorter過濾器/搜索功能的表。現在我試圖向它添加一個滾動條,並使用「純CSS可滾動表格」技術。 (website) 但我不能對齊工作...用的tablesorter&純CSS滾動表

Here's a demo

我這樣設置每列的寬度:

table#eventlist td:nth-child(1), table#eventlist th:nth-child(1) { width: 250px; } 
table#eventlist td:nth-child(2), table#eventlist th:nth-child(2) { width: 250px; } 
table#eventlist td:nth-child(3), table#eventlist th:nth-child(3) { width: 200px; } 
table#eventlist td:nth-child(4), table#eventlist th:nth-child(4) { width: 200px; } 

(我想用滾輪,wedget那我發現在tablesorter網站上,但事實證明,它不工作,因爲它不支持過濾器格式化程序設置。 )

+0

我意識到我可以做出CSS來調整它的一些更多的變化。我認爲它稍微好一點... https://jsfiddle.net/yokonanoda/t671bp8f – yokonanoda

回答

1

這是一個不錯的發現!我必須用這種方法「修復」我的Scroller小部件(我討厭)。

反正固定取向的問題,我發現,這三個寬度設置需要進行設置,盒大小一起。

{ width: 250px; min-width: 250px; max-width: 250px; } 

我更新your demo並作出了一些調整,使水平滾動條不會在Chrome中顯示出來。我不知道如何風格滾動條上方的白色盒子,可是...

#tableContainer * { 
    box-sizing: border-box; 
} 
/* define height and width of scrollable area. Add 16px to width for scrollbar */ 
div.tableContainer { 
    clear: both; 
    height: 340px; 
    overflow-y: auto; 
    overflow-x: hidden; 
    width: 916px 
} 

/* Reset overflow value to hidden for all non-IE browsers. */ 
/* define width of table. Add 16px to width for scrollbar. */ 
html>body div.tableContainer { 
    overflow: hidden; 
    width: 916px 
} 

/* define width of table. IE browsers only */ 
div.tableContainer table { 
    float: left; 
    width: 900px; 
} 

/* All other non-IE browsers. */ 
html>body div.tableContainer table { 
    width: 916px; 
} 

/* set table header to a fixed position. WinIE 6.x only 
In WinIE 6.x, any element with a position property set to relative and is a child 
of an element that has an overflow property set, the relative value translates 
into fixed. 
Ex: parent element DIV with a class of tableContainer has an overflow property 
set to auto 

thead.fixedHeader tr { position: relative } 

set THEAD element to have block level attributes. All other non-IE browsers this 
enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */ 

html>body thead.fixedHeader tr { 
    display: block 
} 

/* define the table content to be scrollable            
set TBODY element to have block level attributes. All other non-IE browsers    
this enables overflow to work on TBODY element. All other non-IE, non-Mozilla 
browsers induced side effect is that child TDs no longer accept 
width: auto */ 
html>body tbody.scrollContent { 
    display: block; 
    height: 262px; 
    overflow-y: auto; 
    overflow-x: hidden; 
    width: 100% 
} 

/* define width of TH elements: 1st, 2nd, and 3rd respectively.  
Add 16px to last TH for scrollbar padding. All other non-IE browsers. */ 
table#eventlist td:nth-child(1), 
table#eventlist th:nth-child(1), 
table#eventlist td:nth-child(2), 
table#eventlist th:nth-child(2) { 
    width: 250px; 
    min-width: 250px; 
    max-width: 250px; 
} 

table#eventlist td:nth-child(3), 
table#eventlist th:nth-child(3), 
table#eventlist td:nth-child(4), 
table#eventlist th:nth-child(4) { 
    width: 200px; 
    min-width: 200px; 
    max-width: 200px; 
} 
+0

哇謝謝Mottie。它好多了!我認爲增加這個可能會解決這個問題。 '表#EVENTLIST THEAD日:第n個孩子(4),表#EVENTLIST THEAD TD:第n個孩子(4){ 寬度:216px; min-width:216px; max-width:216px; }' 它沒有與您的演示http://jsfiddle.net/yokonanoda/tdno8w25/工作,但它定格在我的演示http://jsfiddle.net/ufxrp447/。但底部的滾動條開始出現.. – yokonanoda

+0

我不知道這是一個很好的解決方案,但我調整了最後一個的寬度。 http://jsfiddle.net/k7p7925d/1/現在它完全一致。它適用於我認爲最新的瀏覽器。 我發現了另一個問題(股利高度不調整):在CSS兩個地/ – yokonanoda

+0

變化'height'到'MAX-height':http://jsfiddle.net/Mottie/k7p7925d/3/ – Mottie

1

嘗試添加一個CSS規則將所有設置爲box-sizing: border-box,黑客下面將解決您的定位,但可能是矯枉過正:

* { 
    box-sizing: border-box; 
} 
+0

謝謝Scottux。我試過了,但並沒有真正解決這個問題。 – yokonanoda

+0

奇怪的是,它在我點擊小提琴上的運行時起作用,但當小提琴第一次加載時不起作用。 – Scottux

+0

它給你的代碼看起來更好,但它並不完美。 – yokonanoda

0

我能夠解決類似的對齊問題:

.tablesorter-scroller-header, .tablesorter-scroller-footer { 
    width: 100% !important; /* need this or table and scroller do not align. -ac 11/21/2017 */ 
} 

(添加這裏尋找未來的搜索線索...)