私は1日以上、非常に単純なことを考え出しました。私は約10のテーブルを使用するウェブサイトを持っています。これらの10個のテーブルのうち1つだけに、固定ヘッダーとスクロール可能なバーを持たせたいです。
私はオンラインで良い例を見つけてそれを修正しました。固定ヘッダーとスクロール可能なバーを備えたテーブルを作成できます。
新しいcss
.table-fixed tbody {
display:block;
max-height:625px;
overflow-y: auto;
}
.table-fixed thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
.table-fixed thead {
width: calc( 100% - 1em )
}
テーブル固定クラスをテーブル定義に追加すると、機能します。
<table class = "table table-bordered table-hover table-striped table-condensed table-fixed">
問題は、他のテーブルにテーブル固定を含めないと、他の9つのテーブルがすべて台無しになることです。例えば:
他のテーブルに追加されたテーブル固定クラスはありません
<table class = "table table-bordered table-hover table-striped table-condensed">
<thead>
<tr>
<th style="text-align: center; vertical-align: middle;">something</th>
<th style="text-align: center; vertical-align: middle;">something</th>
<th style="text-align: center; vertical-align: middle;">something</th>
<th style="text-align: center; vertical-align: middle;">something</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center; vertical-align: middle;">something</td>
<td style="text-align: center; vertical-align: middle;">something</td>
<td style="text-align: center; vertical-align: middle;">something</td>
<td style="text-align: center; vertical-align: middle;">something</td>
</tr>
<tbody>
</table>
この問題を修正するにはどうすればよいですか?CSSへの変更が1つのテーブルにのみ影響するようにしたい。テーブル固定クラスは機能しますが、グローバルに影響を与えるtbodyを変更しているようです。これを修正する方法はありますか?
sringlandへのクレジット。
元のコードを変更しました:
.table-fixed tbody {
display:block;
max-height:625px;
overflow-y: auto;
}
.table-fixed thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
.table-fixed thead {
width: calc( 100% - 1em )
}
これに:
.table-fixed > tbody {
display:block;
max-height:625px;
overflow-y: auto;
}
.table-fixed > thead {
display:table;
width:100%;
table-layout:fixed;
}
.table-fixed > tbody > tr {
display:table;
width:100%;
table-layout:fixed;
}
.table-fixed > thead {
width: calc( 100% - 1em )
}
この問題は、クラスのtbodyに影響を与えていたため>
、直接の子にのみ影響し、thead, tbody tr {
定義を分割するように追加することで解決されましたTable
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加