Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed Positioned Div Inside another Div

I have one div position:fixed; and my problem is that position fixed is relatively to all the page, I need that the fixed div stays inside other div that is centered in the page with margins in auto.(So when I scroll down the page I want to see always the div in the same position).

I use the jquery plugin StickyScroll but I can't make it work in Internet Explorer.

The solution could be in jquery/javascript , css.

Thanks

like image 967
Sbml Avatar asked Jun 08 '11 13:06

Sbml


People also ask

How can I make a div fixed inside another div?

Set position: absolute; on the element that you want to position. Set position: relative; on the centered div so that it becomes a layer that you can position elements inside.

How do you get a div to stay in place?

A pinned-down menu. The interesting rule here is the ' position: fixed ', that makes the DIV stay fixed on the screen. The ' top: 50% ' and ' right: 0 ' determine where the DIV is displayed, in this case: 50% down from the top of the window, and a constant 0px from the right.


2 Answers

Then you don't want fixed positioning, but absolute positioning.

Set position: absolute; on the element that you want to position. Set position: relative; on the centered div so that it becomes a layer that you can position elements inside.

like image 191
Guffa Avatar answered Sep 24 '22 18:09

Guffa


You definitely don't need jQuery or JavaScript to achieve this. This is what you need:

.outer {
    width:200px;
    height:600px;
    background-color:red;
    margin:0 auto;
}
.inner {
    width:50px;
    border:1px solid white;
    position:fixed;
}
<div class="outer">
    <div class="inner">some text here
    </div>
</div>

Have a look at this: http://jsfiddle.net/2mYQe/1/

like image 44
George Katsanos Avatar answered Sep 24 '22 18:09

George Katsanos