Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

How to add keep element in view when scrolling

So I have this site and on the right hand side of the container I want to add the registration form so that it stays in view when scrolling. Similar to this. However I am getting a bit confused on how to format the css for the container. Should I simply remove the margin-right : auto; and place my element in the container?

1 Answer

Darrell Conklin
Darrell Conklin
22,377 Points

In order for the container to stay in view while scrolling you need to add

position: fixed;
top: your #;
right: your #;
bottom: your #;
left: your #;

to your container.

Play with the numbers until you've placed the container where you want it. You will not need all 4 values, either top or bottom and right or left.

https://developer.mozilla.org/en-US/docs/Web/CSS/position