4 min read
•Question 20 of 49easyHow Does CSS Overflow Work?
Understanding overflow, text-overflow, and scrolling.
What You'll Learn
- Overflow values
- Text overflow
- Scrolling behavior
Overflow Values
styles.cssCSS
.container {
overflow: visible; /* Default - content spills out */
overflow: hidden; /* Clips content */
overflow: scroll; /* Always shows scrollbar */
overflow: auto; /* Scrollbar when needed */
}
/* Control each axis */
.container {
overflow-x: auto;
overflow-y: hidden;
}Text Overflow
styles.cssCSS
/* Single line ellipsis */
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Multi-line ellipsis */
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}Scroll Behavior
styles.cssCSS
html {
scroll-behavior: smooth;
}
.container {
overscroll-behavior: contain;
}