แปลงตารางแบบคงที่เป็นแบบตอบสนองสำหรับอุปกรณ์เคลื่อนที่

URL คือ http://action.news มี 3 คอลัมน์ในตารางความกว้างคงที่)

(ฉันลบสคริปต์ที่โหลดตามต้องการ) เพื่อให้สิ่งต่าง ๆ ง่ายขึ้น ขอบคุณกรุณา

สิ่งที่ฉันทำไปแล้ว: เพิ่มรหัสนี้ด้านล่าง

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

เพิ่มสิ่งนี้ตามคำแนะนำของ Google

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

ฉันได้อ่าน ตาราง HTML พร้อม auto- เหมาะสำหรับบางคอลัมน์ ความกว้างคงที่สำหรับบางคอลัมน์

แต่ยังไม่สามารถทำให้เพจเป็นมิตรกับมือถือได้ ส่วนบนดูเหมือนจะปรับแนวใหม่


person youtube-dl fan    schedule 10.10.2017    source แหล่งที่มา
comment
เป็นไปได้ไหมที่คุณสามารถใช้ div หรือรายการแทนตารางเพื่อแสดงเนื้อหา? ตารางค่อนข้างยุ่งยากในการตอบสนอง   -  person Laura    schedule 10.10.2017


คำตอบ (1)


ฉันพบตัวอย่างนี้ใน Codepen เพื่อให้คุณสามารถลองใช้และปรับเปลี่ยนตามความต้องการของคุณ:

นี่คือรหัสบางส่วน

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>

ซีเอสเอส:

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;
  }
}

ลิงก์ไปยังตัวอย่าง

person Krusader    schedule 10.10.2017