mengonversi tabel tetap menjadi responsif untuk seluler

URL-nya adalah http://action.news ada 3 kolom dalam tabel dengan lebar tetap)

(saya menghapus skrip yang dimuat sesuai permintaan) untuk mempermudah. terima kasih dengan ramah

apa yang telah saya lakukan: menambahkan kode ini di bawah

https://Gist.github.com/hkirsman/3002480

menambahkan ini sesuai instruksi Google

<meta name=viewport content="width=device-width, initial-scale=1">

saya telah membaca tabel HTML dengan auto- pas untuk beberapa kolom, lebar tetap untuk kolom lainnya

tapi masih belum bisa menjadikan lamannya ramah seluler, bagian atas sepertinya diselaraskan kembali


person youtube-dl fan    schedule 10.10.2017    source sumber
comment
Apakah mungkin Anda bisa menggunakan div atau daftar alih-alih tabel untuk menampilkan konten? Tabel cukup sulit untuk dibuat responsif   -  person Laura    schedule 10.10.2017


Jawaban (1)


Saya menemukan contoh ini di Codepen sehingga Anda dapat mencobanya dan menyesuaikannya dengan kebutuhan Anda:

Ini beberapa kode

HTML:

<table class="js-table participants-table">
  <caption>
    <p>Responsive Table</p>
  </caption>
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Gender</th>
      <th>Picture</th>
    </tr>
  </thead>
  <tbody>
    <!--filled from javascript-->
  </tbody>
</table>

CSS:

HTML {
  font-size: 100%;
  line-height: 1.5;
  font-family: 'Raleway', sans-serif;
}

BODY {
  margin: 0;
}

*, *:before, *:after {
  box-sizing: border-box;
}

IMG {
  max-width: 100%;
}


/*Style For Table*/

.participants-table {
  table-layout: fixed;
  border-collapse: collapse;
  margin: 0 auto;
  width: 90%;
}

.participants-table TD,
.participants-table TH {
  border: 1px solid #b4adad;
}

.participants-table IMG {
  width: 150px;
}

.participants-table THEAD {
  display: none;
}

.participants-table TD {
  display: block;
  position: relative;
  overflow-x: hidden;
  text-overflow: ellipsis;
}


@media only screen and (min-width: 450px) {
  .participants-table {
    width: auto;
  }
  .participants-table TD,
  .participants-table TH {
    padding: .2em 1em;
  }
  .participants-table THEAD {
    display: table-header-group;
  }
  .participants-table TD {
    display: table-cell;
    position: static;
  }
  .participants-table TD:before {
    display: none;
  }
}

tautan ke contoh

person Krusader    schedule 10.10.2017