Bài này trình bày dữ liệu với Bootstrap: bảng kẻ sọc, hover, responsive; danh sách nhóm (list group) dùng cho menu phụ, danh sách việc; ảnh co giãn, ảnh tròn, khung tỉ lệ cho video; và thanh tiến độ, spinner, placeholder khi tải.

40 phútCơ bản
Bạn sẽ học được
  • Định dạng bảng với table-striped, table-hover, table-responsive
  • Dùng list-group có badge, active, hành động
  • Định dạng ảnh: img-fluid, rounded-circle, figure, ratio
  • Dùng progress, spinner, placeholder

Một số khái niệm

Bảng chỉ cần lớp table để có định dạng đẹp; thêm biến thể nếu cần. Bọc bảng trong .table-responsive để cuộn ngang trên điện thoại.

Bảng

<div class="table-responsive"><table class="table table-striped table-hover table-sm align-middle">
  <thead class="table-success"><tr><th>#</th><th>Họ tên</th><th>Lớp</th><th class="text-end">Điểm</th><th>Trạng thái</th></tr></thead>
  <tbody>
    <tr><td>1</td><td>Lò Văn An</td><td>K66 Tin</td><td class="text-end">8.5</td><td><span class="badge text-bg-success">Đạt</span></td></tr>
    <tr><td>2</td><td>Cầm Thị Bình</td><td>K66 Tin</td><td class="text-end">9.0</td><td><span class="badge text-bg-success">Đạt</span></td></tr>
    <tr class="table-danger"><td>3</td><td>Vì Văn Chi</td><td>K65 Tin</td><td class="text-end">4.0</td><td><span class="badge text-bg-danger">Học lại</span></td></tr>
  </tbody></table></div>
Kết quả hiển thị

List group

<div class="row g-3"><div class="col-6"><div class="list-group">
  <a href="#" class="list-group-item list-group-item-action active">Bài 1. Cài đặt</a>
  <a href="#" class="list-group-item list-group-item-action">Bài 2. Lưới</a>
  <a href="#" class="list-group-item list-group-item-action d-flex justify-content-between">Bài 3. Tiện ích <span class="badge text-bg-primary rounded-pill">Mới</span></a></div></div>
<div class="col-6"><ul class="list-group"><li class="list-group-item"><input class="form-check-input me-2" type="checkbox" checked>Đọc bài</li><li class="list-group-item"><input class="form-check-input me-2" type="checkbox">Làm bài tập</li><li class="list-group-item list-group-item-warning">Hạn nộp: thứ Sáu</li></ul></div></div>
Kết quả hiển thị

Ảnh, tỉ lệ, tiến độ, đang tải

<div class="d-flex gap-3 align-items-center mb-3">
  <img src="https://picsum.photos/seed/av1/120" class="rounded-circle" width="64" height="64" alt="">
  <img src="https://picsum.photos/seed/av2/240/140" class="img-thumbnail" width="120" alt="">
  <div class="ratio ratio-16x9 bg-dark rounded" style="width:160px"><div class="d-grid text-white" style="place-items:center">16:9</div></div></div>
<div class="progress mb-2" role="progressbar" aria-valuenow="65" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-success progress-bar-striped progress-bar-animated" style="width:65%">65%</div></div>
<div class="d-flex gap-3 align-items-center"><div class="spinner-border text-success"></div><div class="spinner-grow text-primary"></div>
<p class="placeholder-glow mb-0 flex-fill"><span class="placeholder col-7"></span> <span class="placeholder col-4"></span></p></div>
Kết quả hiển thị
Mẹo hay

Dùng placeholder (khung xám nhấp nháy) thay vì spinner khi tải danh sách: người dùng hình dung được bố cục sắp hiện ra.

Lưu ý

Bảng lớn nhiều cột trên điện thoại khó đọc kể cả khi cuộn ngang; cân nhắc hiển thị dạng thẻ (card) cho màn hình nhỏ.

Thực hành
  1. Hiển thị bảng điểm 10 sinh viên, tô đỏ dòng không đạt.
  2. Tạo menu phụ cho trang khóa học bằng list-group.
  3. Nhúng video YouTube với ratio-16x9.
  4. Làm thanh tiến độ hoàn thành khóa học.
Tóm tắt bài học
  • table + striped/hover/sm, table-responsive.
  • list-group, list-group-item-action, active.
  • img-fluid, rounded-circle, img-thumbnail, ratio.
  • progress, spinner, placeholder cho trạng thái tải.