Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluid width fixed position

Imagine:

<div class="outer">
    <div class="inner">
    </div>
</div>

Where:

  • .outer is part of a column structure, and its width is a percentile and therefore fluid.
  • .inner represents a fixed position element that should fill with a 100% width the .outer element. However its position vertically remains the same, therefore fixed.

I’ve tried to implement this layout with the following CSS:

.outer {
    position: relative;
    width: %;
}
.inner {
    position: fixed;
    width: 100%;
}

However, .inner does not calculate its width as a percentage of its relative parent. Instead it fills the full width of the window/document. Attempting any left or right properties result in the same parent-ignoring qualities.

Is there any way around this?

like image 576
nderjung Avatar asked Sep 03 '12 20:09

nderjung


People also ask

What is fixed positioning?

Fixed positioning is really just a specialized form of absolute positioning; elements with fixed positioning are fixed relative to the viewport/browser window rather than the containing element; even if the page is scrolled, they stay in exactly the same position inside the browser window.

How do you fix a container position?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.

What is the difference between position static and position fixed?

Fixed: The position of the element will be positioned relative to the viewport. Static: The elements will be positioned according to the normal flow of the page. Relative: The element remains in the normal flow of the document but left, right, top, and bottom affects.


1 Answers

.outer {
    position: relative;
    width: %;
}
.inner {
    position: fixed;
    width: inherit;
}

That should do the trick.

like image 166
djones Avatar answered Oct 02 '22 01:10

djones