09. Handling Element Overflow

The overflow property

You can tell CSS how to handle elements that are too large to be contained within its parent container.

We use the propertyoverflow, and the values can be set to hidden, visible, scroll, auto.

#sample {
  width: 18em;
  height: 7em;
  margin: 0 auto 5px;
  border: 2px black solid;
  border-radius: 5px;
  padding: 0.5em;
  overflow: scroll;   /* how container will handle overflow */
}

Scroll

This overflow is set to scroll, with the overflow text clipped.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper ac magna eu sodales. Aliquam nec nibh ut odio interdum egestas quis eget mauris. Donec egestas libero quis velit facilisis sodales. Nullam quis magna vestibulum, accumsan nulla vitae, lobortis diam.

Visible

This overflow is set to visible, meaning the text just goes out of its containing box like it runs the place.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper ac magna eu sodales. Aliquam nec nibh ut odio interdum egestas quis eget mauris. Donec egestas libero quis velit facilisis sodales.

Hidden

This overflow is set to hidden. Notice that the text just cuts off.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper ac magna eu sodales. Aliquam nec nibh ut odio interdum egestas quis eget mauris. Donec egestas libero quis velit facilisis sodales. Nullam quis magna vestibulum, accumsan nulla vitae, lobortis diam.

Auto

This overflow is set to auto, which causes overflowing content to be clipped with a scroll-bar added.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper ac magna eu sodales. Aliquam nec nibh ut odio interdum egestas quis eget mauris. Donec egestas libero quis velit facilisis sodales. Nullam quis magna vestibulum, accumsan nulla vitae, lobortis diam.

Specifying a dimension for overflow

If you'd like to handle just the horizontal or vertical overflow, we can use theoverflow-x andoverflow-y properties.

p {
  overflow-x: hidden;
}

Build modern and responsive webpages

Responsive Typography

Build modern and responsive webpages Try Front-end

Responsive web design helps your site maintain its design integrity on a variety of screen sizes, but how does it affect your typography? With this practical book, graphic designers, web designers, and front-end developers alike will learn the nuts and bolts of how to get the best appearance from type without sacrificing performance on any device.

$ Check price
24.9924.99Amazon 4.5 logo(3+ reviews)

More Front-end resources

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Ad