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

Fixed position

In css i used the fixed position for div, so that the element wouldn't move when scrolled down or up. But unfortunately it didn't stay fixed but moved down or up when I scrolled down or up.

Also, I used Internet Explorer 11, since I know it doesn't work in IE 6.

Yes, that is exactly what I wanted to do.

7 Answers

Hi Sagar, Does your code include a selector for the div element, and the property: value of position: fixed;? Here is a quick example in Codepen: http://codepen.io/anon/pen/vFcCk/ If that doesn't fix your problem, perhaps you could include your source code so I can try to help you better :)

I did the same exact thing except instead of making a div fixed, it was a class that was fixed. The class was a div which included text.

Hey Sagar I would love to help. Can you provide a copy of the code so that I can see what is happening? If possible submit the html and css. Looking forward to assisting you.

Just to be clear, you want the element to always be visible on the screen whether you scroll up or down?

Make sure your css syntax is correct. Right brackets and selectors and correct spelling.

Here's an updated version of the Codepen: http://codepen.io/anon/pen/vFcCk/ Possible issues could be: using an ID selector (#) instead of a class selector, not applying the position: fixed property and value to the correct element (like applying it to the text but not the div), and properly giving that div element the class. Are any of these the issue? If not, perhaps I could look at your code to help you better.

My code included a HTML and external CSS file which was included in the HTML.

HTML file

<!DOCTYPE html> <html> <body> <div class="edit"> This is suppose to be fixed. </div> <div class="edit2"> This is suppose to be fixed, also. </div> </body> </html>

CSS file

.edit{ position:fixed; top:40; left:750; } .edit2{ position:fixed; top:1500; left:750; }

Look at this code pen: http://codepen.io/anon/pen/vFcCk/ I tried including the top and left that you were suggesting, and it seemed to work. Is it not working on your end?

I tried absolute positioning instead of fixed, and it worked after that.

Glad to know you figured it out!