Overflow in learn the box model lesson

Question

In the introduction lesson, says to see how some of the properties affect the elements, and overflow is one of them, but what is Overflow?

Answer
Every element is a box, most often rectangular. But when one element becomes a container, i.e. it contains other elements inside it like a paragraph tag inside a div:


<div>

  <p> Here’s some text </p>

</div>

Then the container (also called parent element) might not always be large enough for the content and then we will need to decide how can we fix that issue. The overflow property helps us with that. It controls what happens to the content when, because of its size in relation to the parent element, it breaks the bounds.

The overflow property has three main values, the default is visible which will allow us to see the container inside of the parent element (also called child) spill over or overflow from the container, the second value is hidden which will hide the part of the child element that would not fit inside the parent, and the third is scroll, which will allow us to have the overflowing text hidden, and it will give us a scroll bar to be able to see it.

22 Likes

Is the word “container” in front of “inside of” a typo and was actually meant to be “content”?

13 Likes

Beautiful explanation, thanks.

7 Likes

oh i get it! but why would we want the overflow to be just hidden? It seems to me that scroll is the best option

2 Likes

The best option is the one that suits the design constraints. There is no fixed best option in the real sense, that’s why HTML/CSS is so flexible.

11 Likes

It is a typo for sure.

2 Likes

like zhangyil - I can’t think of a situation where one would want overflowing content to be not seen (hidden).Could you give an example of that?

2 Likes

There are other property you can add that when it is going to be hidden, u add… for instance so that the user knows there are more stuff

2 Likes

As a designer, I’d imagine I might want to crop a photo in a div and maybe this could be used for that? Or if I was creating artistically with code perhaps!

2 Likes

Well what about those annoying “see more” when you’re reading an article or when you look at IG and you’re not logged in you can see a little scrolling but then after a little bit the IG prompt urges you to login to see more.

5 Likes

I’m not sure that that’s a typo. Containers are a design concept. The whole unit is setting up the whole boxy design idea. But you don’t have to take my word for it. If you right click on whatever web page and use inspect and see the HTML and CSS in developer tools they will have coded in containers for how they want the content inside a specific box (container) to look. That why html has

's to set up your sections so you can style them however you like.

2 Likes

The overflow property has the following values:

  • visible - Default. The overflow is not clipped. The content renders outside the element’s box
  • hidden - The overflow is clipped, and the rest of the content will be invisible
  • scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content
  • auto - Similar to scroll , but it adds scrollbars only when necessary
7 Likes

overflow the way im understanding is any tex that oveflows the box model?
Also theres other values that can be used visible, hidden, scroll and auto which are values used on
css to implement a change in css? please let me know if im on the right track Thank you…

Not just text, background-color or Images could also be bigger than the container they are nested inside of. I’ve also seen some really cool effects done with transparent windows in the foreground that have a scrolling background that is larger than the container it’s in. There is also a scrolling marquee effect that looks pretty cool in the right situation and the overflow for that is hidden as well.

best explanation ever, thanks bro

Hi ngwolfhare,

many thanks for this example and the explanation! :star_struck:
Now I’ve got an idea when to use the value hidden.

I guess thats’s part of Javascript, and this course will come right after CSS. :+1:

kind regards
Ben