Fixed position within div, allowing rest of content to scroll


I have a div that is not at the top of the page. Inside that, I have another div that I need positioned at the top of the parent div so that when the screen is scrolled down, the text box stays at the top of the div and the other content scrolls.

	width: 900px;
	height: 500px;
  	border-style: solid;
        border-width: 5px;



<div class="outer">
	<div class="inner"><input type="text"></div>

Open in new window

If I add    top:0  to the "inner" div, the text box is pinned to the top of the page which is not what I need.

Can someone please help?!

Thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
You just need position:fixed without setting top or left.
kbitAuthor Commented:
But my code above does not work properly?
Duy PhamFreelance IT ConsultantCommented:
See examples in here:

In the first div of above example (using position:fixed), when you scroll content of the parent div, the child div stays at top of parent div. Is that what you expect?

Or do you expect something like in the second div, when scrolling in general (page scrolling, parent content scrolling, etc.), child div always stays at top of parent div? The trick here is use position:absolute to properly align child div with parent div, and wrap other content of parent div in another child div (class="content" which is sibling of fixed child div.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

kbitAuthor Commented:
Thank you very much for your answer. This is close to what I need, but is it possible to do it without a second scrollbar?
Duy PhamFreelance IT ConsultantCommented:
What is second scrollbar do you mean here? If that is scrollbar of content div, you can just remove overflow: auto or change it to overflow: hidden for content div, and align your fixed child div accordingly (e.g.: change to right:0px).
kbitAuthor Commented:
Sounds good, thanks for your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.