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?
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.
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.
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.
.outer {
position: relative;
width: %;
}
.inner {
position: fixed;
width: inherit;
}
That should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With