📦 Overflow = Content Handling
Content overflows containers. Overflow controls how to handle it. Scroll, hidden, visible — choose wisely.
📝 Overflow Values
/* Visible (default) */
overflow: visible;
/* Content overflows container */
/* Hidden */
overflow: hidden;
/* Content clipped, no scroll */
/* Scroll */
overflow: scroll;
/* Always show scroll bars */
/* Auto */
overflow: auto;
/* Show scroll bars if needed */
/* Individual axes */
overflow-x: hidden;
overflow-y: scroll;
/* Text overflow */
text-overflow: ellipsis; /* ... */
text-overflow: clip;
white-space: nowrap;
/* Example: Truncate text */
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px;
}
/* Scrollable container */
.scrollable {
overflow: auto;
max-height: 300px;
}
/* Hidden scroll (overflow only) */
.hide-scroll {
overflow: hidden;
max-height: 200px;
}
🎯 Practical Examples
/* Card with overflow */
.card {
overflow: hidden;
border-radius: 8px;
}
.card-image {
width: 100%;
height: 200px;
object-fit: cover;
}
/* Scrollable table */
.table-container {
overflow-x: auto;
max-width: 100%;
}
/* Dropdown menu */
.dropdown-content {
overflow-y: auto;
max-height: 200px;
}
/* Modal content */
.modal-body {
overflow-y: auto;
max-height: 80vh;
padding: 20px;
}
/* Text truncation (multi-line) */
.multiline-truncate {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* Responsive overflow */
@media (max-width: 768px) {
.container {
overflow-x: auto;
}
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
💡 Overflow Tips
- Use auto for dynamic content
- Use hidden for clean layouts
- Use scroll for guaranteed scrolling
- Use ellipsis for text truncation
- Customize scrollbar styling
“Overflow controls content handling. Scroll, hidden, visible. Essential for layout control.”
