【发布时间】:2019-04-24 06:15:16
【问题描述】:
The Table with bad text-alignment
在图片中,您会看到文本对齐错误的表格。 tbody 的元素与 thead 的元素不匹配。固定表头很重要,这样即使向下滚动也能看到它。
我用于此表的类是 table-hover 和我自己的类“table_Bookingsystem”,其属性如下所列
.table_Bookingsystem{
table-layout: fixed;
border-collapse: collapse;
width: 100%;
margin-left: auto;
margin-right: auto;
text-align: left;
padding-top: 16px;
padding-bottom: 16px;
border: 1px solid #ccc !important;
}
.table_Bookingsystem tbody{
display:block;
width: 100%;
overflow: auto;
}
.table_Bookingsystem thead tr {
display: block;
}
.table_Bookingsystem tr{
border-bottom: 1px solid #ddd;
}
.table_Bookingsystem thead {
background: black;
color:#fff;
}
.table_Bookingsystem th, .table_Bookingsystem td {
padding: 5px;
text-align: center;
width: 5000px; //important line
}
.table_Bookingsystem tbody tr:nth-child(even) {
background-color: #e4ebf2;
color: #000;
}
<table class="table_Bookingsystem table-hover ">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Auto</th>
<th scope="col">IMEI</th>
<th scope="col">Heimatstadt</th>
<th scope="col">derzeitige Stadt</th>
</tr>
</thead>
<tbody @if(count($cars) > 9) style="height: 300px;" @endif>
@foreach($cars as $car)
<tr class="table-row clickable-row" data-href='/cars/{{$car->id}}'>
<th>{{$loop->iteration}}</th>
<td>{{$car->name}}</td>
<td>{{$car->IMEI}}</td>
<td>
<?php
$city = Illuminate\Support\Facades\DB::table('cities')->where('id','=', $car->id_homeCity)->get('name');
echo $city[0]->name; ?>
</td>
<td>
<?php
$city = Illuminate\Support\Facades\DB::table('cities')->where('id','=', $car->id_currentCity)->get();
echo $city[0]->name; ?>
</td>
</tr>
@endforeach
</tbody>
</table>
当我将宽度设置为 250 像素时,它看起来会好一些,但是当我只有 4 列或更少的列时,就会有很大的优势。有没有什么办法可以保留固定的header,把每个-element 直接放在对应的-element 下?
【问题讨论】:
-
请在上面的代码 sn-p 中添加 HTML。谢谢
-
我现在做了,问题是我使用 laravel 和刀片模板,无法在此处执行
标签: html css laravel css-tables