31. Overflow, Text Truncation, Lists & Table Styling

🟢 Beginner

1. Definition

overflow (visible, hidden, scroll, auto) controls box clipping. Text truncation (text-overflow: ellipsis) truncates long strings. list-style: none removes bullet markers, and border-collapse: collapse creates clean data tables.

2. Why It Is Used

Overflow properties prevent content boxes from breaking page layouts when user-generated text exceeds container bounds.

3. How It Works

Combining white-space: nowrap; overflow: hidden; text-overflow: ellipsis; truncates overflowing single-line text with an ellipsis (...).

4. Syntax

.truncate-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-clean {
  border-collapse: collapse;
  width: 100%;
}

5. Overflow Values Reference Table

ValueBehavior
visibleDefault; content renders outside container box
hiddenClips overflowing content without scrollbars
scrollAlways displays scrollbars regardless of overflow
autoDisplays scrollbars ONLY when content overflows

6. Beginner Example

.scroll-box {
  max-height: 200px;
  overflow-y: auto;
}

7. Intermediate Example

.clean-table {
  width: 100%;
  border-collapse: collapse;
}

.clean-table th, .clean-table td {
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
}

8. Advanced Multi-line Text Truncation Example

.truncate-3-lines {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

9. Line-by-Line Code Explanation

  • -webkit-line-clamp: 3;: Truncates paragraph text after exactly 3 lines, adding trailing ellipsis (...).

10. Expected Terminal / Browser Output

Clean single-line or multi-line text cards and striped data tables without broken layout boxes.

11. Common Mistakes & Pitfalls

  • Using overflow: scroll instead of auto: scroll forces permanent scrollbars even when content fits inside the container. Use auto.

12. Important Rules & Limitations

  • Single-line text-overflow: ellipsis requires setting overflow: hidden and white-space: nowrap.

13. Multilingual Explanation: English

overflow: auto adds scrollbars when content overflows. Use text-overflow: ellipsis for text truncation.

14. Multilingual Explanation: Hindi (Roman Script)

Content box se bahar jaane par overflow: auto scrollbar deta hai. Text truncate karne ke liye text-overflow: ellipsis ka use karein.

15. Multilingual Explanation: Marathi (Roman Script)

Overflow content sathi overflow: auto vapara ani extra text truncate karnyasathi text-overflow: ellipsis vapara.

16. Practice Questions

  1. What three CSS properties are required for single-line text truncation with an ellipsis?

17. Practical Coding Challenge

Create a .card-description class that truncates text to 2 lines using -webkit-line-clamp: 2.

18. Related Topics