我有一個帶有滾動條的表格,當我過濾表格時,滾動條未顯示,這對我有好處,但問題是寬度正在變化,並且表格寬度變大。 它看起來像這樣:
有捲軸:
沒有捲軸,過濾後:
這是我的CSS程式碼:
.table { table-layout: fixed; width: 100% !important; } tbody { display: block; height: 326px; overflow: auto; width: 1205px; } thead, tbody tfoot, tr { display: table; width: 100%; table-layout: fixed; /* even columns width , fix width of table too*/ } thead { table-layout: fixed; } .table tr th:nth-child(1), .table tr td:nth-child(1) { width: 30px !important; } .table tr th:nth-child(2), .table tr td:nth-child(2) { width: 90px !important; } .table tr th:nth-child(3), .table tr td:nth-child(3) { width: 100px !important; } .table tr th:nth-child(4), .table tr td:nth-child(4) { width: 90px !important; } .table tr th:nth-child(5), .table tr td:nth-child(5) { width: 90px !important; } .table tr th:nth-child(6), .table tr td:nth-child(6) { width: 90px !important; } .table tr th:nth-child(7), .table tr td:nth-child(7) { width: 85px !important; } .table tr th:nth-child(8), .table tr td:nth-child(8) { width: 90px !important; } .table tr th:nth-child(9), .table tr td:nth-child(9) { width: 110px !important; } .table tr th:nth-child(10), .table tr td:nth-child(10) { width: 95px !important; }
如何解決我的問題?
如果您想確保元素在出現捲軸時不會移動,請在套用了溢出屬性的元素上使用
scrollbar-gutter:stable
。見下文。MDN 上的捲軸裝訂線 p>