Membuat Tabel Responsive dengan CSS

Membuat Tabel Responsive dengan CSS

Pada umumnya tabel dari Blogger terkesan sangat kaku dan memiliki desain yang seadanya, untuk itu kita dapat mendesainnya menggunakan CSS pada template. Berikut adalah caranya.

Cara I (External CSS)

1. Masuk ke Pengaturan Tema Blogger, Pilih Edit HTML,
2. Pastekan Kode berikut ini tepat di atas kode ]]></b:skin>
/* CSS Tabel */
table,caption,tbody{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}
table{border-collapse:collapse;border-spacing:0;}
.post-body table td,.post-body table caption{border:1px solid #e9e9e9;padding:7px;text-align:left;vertical-align:top;}
.post-body table tr th {border:1px solid #6f7785;color:#fff;padding:8px 8px;text-align:left;vertical-align:top;font-size:12px}
.post-body table th {background:#747d8c;}
.post-body table tr th:hover{background:#57606f}
.post-body table.tr-caption-container {border:1px solid #f6f8f9;}
.post-body table caption{border:none;font-style:italic;}
.post-body td, .post-body th{color:#57606f;vertical-align:top;text-align:left;font-size:12px;padding:3px 5px;}
.post-body table tr:nth-child(even) > td {background-color:#dedede;}
.post-body table tr:nth-child(odd) > td {background-color:#f6f8f9;}
.post-body td a{color:#768187;padding:0 6px;font-size:85%;float:right;display:inline-block;border-radius:3px}
.post-body td a:hover {color:#7f9bdf;border-color:#adbce0;}
.post-body td a[target="_blank"]:after {margin-left:5px;}
.post-body table.tr-caption-container td {border:none;padding:8px;}
.post-body table.tr-caption-container, .post-body table.tr-caption-container img, .post-body img {max-width:100%;height:auto;}
.post-body td.tr-caption {color:#666;font-size:80%;padding:0px 8px 8px !important;}
table {max-width:100%;width:100%;margin:0.5em auto;}
table.section-columns td.first.columns-cell{border-left:none}
table.section-columns{border:none;table-layout:fixed;width:100%;position:relative}
table.columns-2 td.columns-cell{width:50%}
table.columns-3 td.columns-cell{width:33.33%}
table.columns-4 td.columns-cell{width:25%}
table.section-columns td.columns-cell{vertical-align:top}
table.tr-caption-container{padding:4px;margin-bottom:.5em}
td.tr-caption{font-size:75%}
.post-body table tr:hover td {background:#b0b1b4;color:#FFFFFF;border-top: 1px solid #22262e;}
table tr:nth-child(odd):hover td {background:#b0b1b4;}
3. Simpan Tema.

Bagaimana Cara menggunakannya?
1. Buat postingan baru,
2. Masuk ke Mode HTML
3. Masukkan kode dasar tabel. seperti dibawah ini:
 <table>
      <tr>
        <th>Header</th>
        <th>Header</th>
      </tr>
      <tr>
        <td>Baris 1 Kolom 1</td>
        <td>Baris 1 Kolom 2</td>
      <tr>
        <td>Baris 2 Kolom 1</td>
        <td>Baris 2 Kolom 2</td>
      </tr>
  </table> 


Preview hasil:
Header Header
Baris 1 Kolom 1 Baris 1 Kolom 2
Baris 2 Kolom 1 Baris 2 Kolom 2


Cara tersebut berguna untuk mengganti seluruh tabel pada postingan maupun halaman blogger.
Bagaimana jika ingin menggunakannya hanya untuk satu postingan saja? Berikut adalah langkah-langkahnya:

Cara II (Internal CSS)

1. Copy kode CSS berikut.
2. Buka postingan lalu ubah dalam bentuk HTML View. lalu tempel.
 <style type="text/css">
table,caption,tbody{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}
table{border-collapse:collapse;border-spacing:0;}
.post-body table td,.post-body table caption{border:1px solid #e9e9e9;padding:7px;text-align:left;vertical-align:top;}
.post-body table tr th {border:1px solid #6f7785;color:#fff;padding:8px 8px;text-align:left;vertical-align:top;font-size:12px}
.post-body table th {background:#747d8c;}
.post-body table tr th:hover{background:#57606f}
.post-body table.tr-caption-container {border:1px solid #f6f8f9;}
.post-body table caption{border:none;font-style:italic;}
.post-body td, .post-body th{color:#57606f;vertical-align:top;text-align:left;font-size:12px;padding:3px 5px;}
.post-body table tr:nth-child(even) > td {background-color:#dedede;}
.post-body table tr:nth-child(odd) > td {background-color:#f6f8f9;}
.post-body td a{color:#768187;padding:0 6px;font-size:85%;float:right;display:inline-block;border-radius:3px}
.post-body td a:hover {color:#7f9bdf;border-color:#adbce0;}
.post-body td a[target="_blank"]:after {margin-left:5px;}
.post-body table.tr-caption-container td {border:none;padding:8px;}
.post-body table.tr-caption-container, .post-body table.tr-caption-container img, .post-body img {max-width:100%;height:auto;}
.post-body td.tr-caption {color:#666;font-size:80%;padding:0px 8px 8px !important;}
table {max-width:100%;width:100%;margin:0.5em auto;}
table.section-columns td.first.columns-cell{border-left:none}
table.section-columns{border:none;table-layout:fixed;width:100%;position:relative}
table.columns-2 td.columns-cell{width:50%}
table.columns-3 td.columns-cell{width:33.33%}
table.columns-4 td.columns-cell{width:25%}
table.section-columns td.columns-cell{vertical-align:top}
table.tr-caption-container{padding:4px;margin-bottom:.5em}
td.tr-caption{font-size:75%}
.post-body table tr:hover td {background:#b0b1b4;color:#FFFFFF;border-top: 1px solid #22262e;}
table tr:nth-child(odd):hover td {background:#b0b1b4;}
</style>  
Hasilnya akan sama, namun cara kedua ini hanya berfungsi untuk merubah tabel pada satu postingan saja

0 comments:

Posting Komentar

Komen dong