Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative positioned div inside of fixed parent

I need relative positioned div inside of fixed parent.

I have a website where everything is relative exept fixed popup window which opens on a button click. This popup window should be 100% width and 100% height, so it covers whole page.

Inside popup window I want fixed div on left side which is 60% width, and relative div on right side (40% width, auto height) which is available to scroll.

In fact, it's hard to explain so I made the fiddle. In this example, I want to scroll orange div instead of scrolling blue div. Is it possible to change scrollbar focus?

<div id='container'>
  <div id='inside-fixed-div'>
    <div id='left-fixed-container'></div>
    <div id='right-relative-container'>
    </div>
  </div>
</div>

https://jsfiddle.net/87x8dwn6/

like image 775
Fale1994 Avatar asked Jan 31 '26 11:01

Fale1994


1 Answers

To remove the scroll on the blue, I needed to remove the 1200px height set on the #container and replace that value with 100%. The 100% height won't work unless the parent is also 100% height. Because of this, the parents needing this 100% height would be the document root and body.

html, body {
  margin: 0;
  height: 100%;
}

#container{
  ...
  height: 100%;
}

In addition, I set overflow to auto and height to 100% on #right-relative-container.

#right-relative-container{
  ...
  height: 100%;
  overflow: auto;
  ...
}

Result (quality of gif isn't great — apologies)

enter image description here

Demo http://codepen.io/antibland/pen/eZjxom

like image 71
Andy Hoffman Avatar answered Feb 03 '26 05:02

Andy Hoffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!