FAQ: The Box Model - Overflow


#1

This community-built FAQ covers the “Overflow” exercise from the lesson “The Box Model”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn CSS

FAQs on the exercise Overflow

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Why does the class. “share” height change when I type in the #main ID a height of 1000px?


#3

Not clear on your question. .share is independent of #main so should see no effect. Can you illustrate your question with a before and after screen grab?


#4

I believe the above poster is asking why when there is no overflow property declared on #main, and the height is set to 1000px, that the position of .share changes to the center of our #main div. I too was wondering why this seems to so drastically change the placement of our .share div.


#5

That is a positioning problem we should be able to sort out once we see your style sheet. Please post style.css.

Belay, belay. I have reproduced your example and will need to ponder awhile the reason why we see this behavior.


Here’s one thought… Because the height is set to 1000px on #main, and both it and .share have position: relative; properties, the latter is positioning itself 1000px down from the banner.

Recall that HTML is greedy when it comes to page length. The DIV will stretch to whatever length it needs to accomodate the content. However once we introduce height we exceed this paradigm by imposing artificial limits. Strange behavior should be expected, which we witness here. Take the height property away from #main and the behavior will be natural.

Bottom line, we should always impose an overflow rule if we expect the content to exceed our prescribed height.


#6

I tried to play about with this too, I tried to change the positioning of the elements to try and overcome the issue to no avail. The only rule set that moved to element was position: fixed; which moved the element out of sight, essentially hidden. Is this down to the same issue (The unexpected results of html trying to compensate for the overspill?


#7

We should not have to change the position property for this demo to work. Simply impose a height that is less than what is needed to contain all the content in #main, and add an overflow:scroll property. Save and examine the output.


#8

Sorry i think you misunderstood my question. I had already completed the lesson and succeeded. I just wanted to see if I could get the element to stay at the bottom of the page… I’ve learnt a bit more about CSS now and understand that “fixed: position;” is fixed relative to the viewport and the values one sets. At the time i misunderstood what position: fixed; rule actually did. I was going on the assumption that it fixed it in the position where it was placed in the code…


#9

Had I tried to explain what you discovered, would it have been as effective? I didn’t misunderstand your question, but evaded it. Now of your own volition you have a better understanding of position. No doubt static came into that.

When we wish to fix something relative to a parent container that is not the body, then that container must be position: relative. A position: absolute property on a child of that container will adhere to the parent top and left boundaries.

Fixing relates to the browser viewport, not just the element viewport. It has plenty of uses, though a design will naturally work around the constraints of a fixed element. We can fix elements to the left and right side, as well, not just top and bottom.