-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)
overflow
in CSS?In CSS, the overflow
property specifies what should happen if the content of an element overflows its defined area (e.g., if content is too large to fit in a box).
Sometimes content inside an element grows beyond its width or height. To handle this, we use overflow
to decide whether:
It should be visible
Hidden
Scrollable
Or handled automatically
selector {
overflow: value;
}
Possible values:
visible
(default)
hidden
scroll
auto
visible
(Default)This is the default behavior. Content that overflows will still be visible outside the container.
<div class="visible-box">
This is some very long content that will overflow its box but will still be visible outside.
</div>
.visible-box {
width: 200px;
height: 50px;
overflow: visible;
border: 1px solid black;
}
🟢 The content overflows and sticks out beyond the box.
hidden
This value clips the overflowing content and makes it invisible. Scrollbars are not added.
<div class="hidden-box">
This is long content that will be cut off.
</div>
.hidden-box {
width: 200px;
height: 50px;
overflow: hidden;
border: 1px solid red;
}
🟢 Any content that doesn’t fit within the 200×50 box will be hidden.
scroll
This value adds scrollbars always, regardless of whether the content overflows or not.
<div class="scroll-box">
This content is scrollable even if it doesn't overflow!
</div>
.scroll-box {
width: 200px;
height: 50px;
overflow: scroll;
border: 1px solid blue;
}
🟢 Scrollbars will always appear, even if not needed.
auto
This value automatically adds scrollbars only when needed.
<div class="auto-box">
This content will show scrollbars only if it overflows the box.
</div>
.auto-box {
width: 200px;
height: 50px;
overflow: auto;
border: 1px solid green;
}
🟢 Scrollbars appear only when content is larger than the box.
You can also control overflow separately for horizontal and vertical directions using:
overflow-x
overflow-y
.div1 {
overflow-x: scroll; /* horizontal scroll only */
overflow-y: hidden; /* vertical overflow hidden */
}
<div class="scroll-menu">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
<a href="#">Link 4</a>
</div>
.scroll-menu {
white-space: nowrap;
overflow-x: auto;
border: 1px solid #ccc;
width: 300px;
}
.scroll-menu a {
display: inline-block;
padding: 10px;
}
🟢 This creates a horizontal scroll menu.
Creating scrollable boxes
Hiding overflowing content
Adding horizontal scrolling
Responsive card layouts
Avoiding layout breaking due to long text
Q1. Create a box with overflow: hidden
.
Q2. Allow vertical scroll and hide horizontal scroll.
Q3. Create a box that always shows scrollbars.
Q4. Create a box where scrollbars appear only when needed.
Q5. Hide overflow text from a div with fixed width.
Q6. Make an image scrollable inside a container.
Q7. Prevent horizontal overflow using overflow-x
.
Q8. Create a horizontal menu that scrolls.
Q9. Hide overflow and round the corners.
Q10. Combine white-space: nowrap
and overflow-x: auto
.
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)