1. Главная / Блог / CSS / CSS стили для таблиц

CSS стили для таблиц


Нет комментариев.


На странице представлены готовые примеры стилей CSS для html таблиц сайта.


Возьмём одну простую таблицу, к которой будем подключать различные стили.

Простая таблица

<table class="table">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>ZIP</th>
</tr>
</thead>
<tbody>
<tr>
<td>Gloria</td>
<td>Reeves</td>
<td>67439</td>
</tr>
<tr>
<td>Graham</td>
<td>Bonner</td>
<td>46359</td>
</tr>
<tr>
<td>Warren</td>
<td>Wheeler</td>
<td>61754</td>
</tr>
</tbody>
</table>

Стандартная таблица

.table {
width: 100%;
margin-bottom: 20px;
border: 1px solid #dddddd;
border-collapse: collapse;
}
.table th {
font-weight: bold;
padding: 5px;
background: #efefef;
border: 1px solid #dddddd;
}
.table td {
border: 1px solid #dddddd;
padding: 5px;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Стандартная таблица с зеброй

.table{
border: 1px solid #eee;
table-layout: fixed;
width: 100%;
margin-bottom: 20px;
}
.table th {
font-weight: bold;
padding: 5px;
background: #efefef;
border: 1px solid #dddddd;
}
.table td{
padding: 5px 10px;
border: 1px solid #eee;
text-align: left;
}
.table tbody tr:nth-child(odd){
background: #fff;
}
.table tbody tr:nth-child(even){
background: #F7F7F7;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Таблица без боковых рамок

.table {
width: 100%;
margin-bottom: 20px;
border-collapse: collapse;
}
.table th {
font-weight: bold;
padding: 5px;
background: #efefef;
border: 1px solid #dddddd;
}
.table td {
border: 1px solid #dddddd;
padding: 5px;
}
.table tr td:first-child, .table tr th:first-child {
border-left: none;
}
.table tr td:last-child, .table tr th:last-child {
border-right: none;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Толстые рамки

.table {
width: 100%;
margin-bottom: 20px;
border: 15px solid #F2F8F8;
border-top: 5px solid #F2F8F8;
border-collapse: collapse;
}
.table th {
font-weight: bold;
padding: 5px;
background: #F2F8F8;
border: none;
border-bottom: 5px solid #F2F8F8;
}
.table td {
padding: 5px;
border: none;
border-bottom: 5px solid #F2F8F8;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Двойная рамка

.table {
width: 100%;
margin-bottom: 20px;
border: 5px solid #fff;
border-top: 5px solid #fff;
border-bottom: 3px solid #fff;
border-collapse: collapse;
outline: 3px solid #ffd300;
font-size: 15px;
background: #fff!important;
}
.table th {
font-weight: bold;
padding: 7px;
background: #ffd300;
border: none;
text-align: left;
font-size: 15px;
border-top: 3px solid #fff;
border-bottom: 3px solid #ffd300;
}
.table td {
padding: 7px;
border: none;
border-top: 3px solid #fff;
border-bottom: 3px solid #fff;
font-size: 15px;
}
.table tbody tr:nth-child(even){
background: #f8f8f8!important;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Вертикальные разделители

.table {
width: 100%;
border: none;
margin-bottom: 20px;
}
.table thead th {
font-weight: bold;
text-align: left;
border: none;
padding: 10px 15px;
background: #d8d8d8;
font-size: 14px;
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
}
.table tbody td {
text-align: left;
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
padding: 10px 15px;
font-size: 14px;
vertical-align: top;
}
.table thead tr th:first-child, .table tbody tr td:first-child {
border-left: none;
}
.table thead tr th:last-child, .table tbody tr td:last-child {
border-right: none;
}
.table tbody tr:nth-child(even){
background: #f3f3f3;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Закругленные углы рамки

.table {
width: 100%;
border: none;
margin-bottom: 20px;
border-collapse: separate;
}
.table thead th {
font-weight: bold;
text-align: left;
border: none;
padding: 10px 15px;
background: #EDEDED;
font-size: 14px;
border-top: 1px solid #ddd;
}
.table tr th:first-child, .table tr td:first-child {
border-left: 1px solid #ddd;
}
.table tr th:last-child, .table tr td:last-child {
border-right: 1px solid #ddd;
}
.table thead tr th:first-child {
border-radius: 20px 0 0 0;
}
.table thead tr th:last-child {
border-radius: 0 20px 0 0;
}
.table tbody td {
text-align: left;
border: none;
padding: 10px 15px;
font-size: 14px;
vertical-align: top;
}
.table tbody tr:nth-child(even) {
background: #F8F8F8;
}
.table tbody tr:last-child td{
border-bottom: 1px solid #ddd;
}
.table tbody tr:last-child td:first-child {
border-radius: 0 0 0 20px;
}
.table tbody tr:last-child td:last-child {
border-radius: 0 0 20px 0;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Таблица полосками

.table {
width: 100%;
border: none;
margin-bottom: 20px;
}
.table thead th {
font-weight: bold;
text-align: left;
border: none;
padding: 10px 15px;
background: #d8d8d8;
font-size: 14px;
}
.table thead tr th:first-child {
border-radius: 8px 0 0 8px;
}
.table thead tr th:last-child {
border-radius: 0 8px 8px 0;
}
.table tbody td {
text-align: left;
border: none;
padding: 10px 15px;
font-size: 14px;
vertical-align: top;
}
.table tbody tr:nth-child(even){
background: #f3f3f3;
}
.table tbody tr td:first-child {
border-radius: 8px 0 0 8px;
}
.table tbody tr td:last-child {
border-radius: 0 8px 8px 0;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Горизонтальные линии

.table {
width: 100%;
border: none;
margin-bottom: 20px;
}
.table thead th {
padding: 10px;
font-weight: 500;
font-size: 16px;
line-height: 20px;
text-align: left;
color: #444441;
border-top: 2px solid #716561;
border-bottom: 2px solid #716561;
}
.table tbody td {
padding: 10px;
font-size: 14px;
line-height: 20px;
color: #444441;
border-top: 1px solid #716561;
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Адаптивная таблица

.table {
border-radius: 5px;
font-size: 12px;
font-weight: normal;
border: none;
border-collapse: collapse;
width: 100%;
max-width: 100%;
white-space: nowrap;
background-color: white;
}
.table td, .fl-table th {
text-align: center;
padding: 8px;
}
.table td {
border-right: 1px solid #f8f8f8;
font-size: 12px;
}
.table thead th {
color: #ffffff;
background: #4FC3A1;
}
.table thead th:nth-child(odd) {
color: #ffffff;
background: #324960;
}
.table tr:nth-child(even) {
background: #F8F8F8;
}
/* Responsive */
@media (max-width: 767px) {
.table {
display: block;
width: 100%;
}
.table-wrapper:before{
content: "Scroll horizontally";
display: block;
text-align: right;
font-size: 11px;
color: white;
padding: 0 0 10px;
}
.table thead, .fl-table tbody, .fl-table thead th {
display: block;
}
.table thead th:last-child{
border-bottom: none;
}
.table thead {
float: left;
}
.table tbody {
width: auto;
position: relative;
overflow-x: auto;
}
.table td, .fl-table th {
padding: 20px .625em .625em .625em;
height: 60px;
vertical-align: middle;
box-sizing: border-box;
overflow-x: hidden;
overflow-y: auto;
width: 120px;
font-size: 13px;
text-overflow: ellipsis;
}
.table thead th {
text-align: left;
border-bottom: 1px solid #f7f7f9;
}
.table tbody tr {
display: table-cell;
}
.table tbody tr:nth-child(odd) {
background: none;
}
.table tr:nth-child(even) {
background: transparent;
}
.table tr td:nth-child(odd) {
background: #F8F8F8;
border-right: 1px solid #E6E4E4;
}
.table tr td:nth-child(even) {
border-right: 1px solid #E6E4E4;
}
.table tbody td {
display: block;
text-align: center;
}
}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Закруглённые ячейки

.table {width: 100%; border-collapse: separate; border-spacing: 4px;}
.table thead tr {color: #ffffff; font-weight: bold;}
.table thead tr td {border-radius: 4px 4px 0 0; background: #2e82c3;}
.table tbody tr td {border: 1px solid #2e82c3; border-radius: 4px; background: #cbdfef;}
.table tbody tr td:hover {background: #a2c3dd; transition-duration: 0.2s;}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754

Изменение цвета строк при наводе мыши

.table {width: 100%; text-align: center; border-bottom: 2px solid #dfdfdf; border-radius: 6px; border-collapse: separate; border-spacing: 0px;}
.table thead tr {color: #ffffff; font-weight: bold; background: #c83240;}
.table tr td {border-right: 1px solid #dfdfdf;}
.table tr td:last-child {border-right: 0px;}
.table tbody tr:nth-child(1n) {background: #f6f6f6;}
.table tbody tr:nth-child(2n) {background: #e6e6e6;}
.table tbody tr:hover {background: #ffe8e8; transition-duration: 0.6s;}

Пример:

First Name Last Name ZIP
Gloria Reeves 67439
Graham Bonner 46359
Warren Wheeler 61754


Нет комментариев.


Оставить комментарий

Ваше имя:

Оценка