Fixed position within div, allowing rest of content to scroll

Hi,

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.

<style>
.outer
{
	position:relative;
	width: 900px;
	height: 500px;
  	border-style: solid;
        border-width: 5px;
}

.inner
{
	position:fixed;
}

</style>

<br><br><br><br><br><br><br><br><br><br><br><br>
<div class="outer">
	<div class="inner"><input type="text"></div>
	<br>
	other
	<br>
	content
	<br>
	goes
	<br>
	here
</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
kbitAsked:
Who is Participating?
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.
0
kbitAuthor Commented:
But my code above does not work properly?
0
Duy PhamFreelance IT ConsultantCommented:
See examples in here: http://jsfiddle.net/sj856uaq/1/.

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.
0

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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?
0
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).
0
kbitAuthor Commented:
Sounds good, thanks for your help
0
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
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.