πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Table Styling

Web Styles🟒 Free Lesson

Advertisement

Table Styling

Table layouts, responsive tables, striped rows, and sortable headers.

Overview

Well-styled tables display data clearly.

Key Concepts

  • Table Layout β€” Fixed vs auto
  • Striped Rows β€” Alternating colors
  • Hover Effects β€” Row highlighting
  • Responsive β€” Horizontal scroll
  • Sticky Headers β€” Fixed headers

Code Examples

/* Base table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

.table th {
  background: #f8f9fa;
  font-weight: 600;
  position: sticky;
  top: 0;
}

/* Striped rows */
.table-striped tbody tr:nth-child(even) {
  background: #f8f9fa;
}

/* Hover effect */
.table-hover tbody tr:hover {
  background: #e9ecef;
}

/* Bordered table */
.table-bordered {
  border: 1px solid #ddd;
}

.table-bordered th,
.table-bordered td {
  border: 1px solid #ddd;
}

/* Responsive table */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Compact table */
.table-compact th,
.table-compact td {
  padding: 0.5rem;
  font-size: 0.875rem;
}

/* Sortable headers */
.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable::after {
  content: '↕';
  margin-left: 0.5rem;
  opacity: 0.3;
}

.sortable.asc::after {
  content: ' ^';
  opacity: 1;
}

.sortable.desc::after {
  content: ' v';
  opacity: 1;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }

/* Actions column */
.table-actions {
  display: flex;
  gap: 0.5rem;
}

.table-actions button {
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Fixed column */
.table-fixed {
  table-layout: fixed;
}

.table-fixed col:first-child {
  width: 200px;
}

/* Sticky first column */
.table-sticky th:first-child,
.table-sticky td:first-child {
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
}

.table-sticky th:first-child {
  z-index: 2;
}

Practice

Build a responsive data table with sorting and filtering.

⭐

Premium Content

Table Styling

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement