Link to home
Start Free TrialLog in
Avatar of kbit
kbit

asked on

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
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

You just need position:fixed without setting top or left.
Avatar of kbit
kbit

ASKER

But my code above does not work properly?
ASKER CERTIFIED SOLUTION
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kbit

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kbit

ASKER

Sounds good, thanks for your help