Since when do absolute positioned elements grow the document - css

I just stumbled over a strange behaviour.
I have a div which is positioned absolute. The element is positioned to lay outside the body and the document grows.
That's confusing to me, since I always thought, that absolute positioned elements get out of the flow.
Has this changed somewhen or do I get something wrong?
I tested it in Chrome 51 and FF 46.
HTML:
<div id="container"></div>
CSS:
#container {
position: absolute;
width: 100%;
right: -2em;
top: 102vh;
}
Here's the fiddle.
Thanks in advance!

Add this to your CSS:
body {
overflow: hidden;
}

Related

allow overflow on fixed positioned element

I have a fixed positioned element somewhere near bottom of my page. As there is more content to it than window height itself displays rest of it's been cut down.
I've tried adding overflow:auto to fix this issue and be capable of scrolling through fixed positioned element but no luck.
I suppose there might be a javascript solution near by but wondering if there is a css one as well.
Hope my question made sense.
Thanks
You have to fix the height/width to get scrollbars, otherwise the fixed element expands out of view. Here's a little demo: little link. Basic outine:
HTML:
<div class = "fixed">
Glee is awesome!<br/>
...
Glee is awesome!<br/>
</div>
CSS:
html, body {
height: 100%;
}
.fixed {
position: fixed;
left: 0px;
top: 0px;
height: 100%;
width: 100px;
overflow: auto;
}

How can I make an element on a webpage fixed BUT relative to another element?

I have an element that is fixed and has a margin from the left of the screen. I want to make this element right of a wrapper instead because people who have smaller resolutions or larger will have the element really far away or really close to my wrapper.
I hope this makes sense! :S
Thanks
Using both fixed and relative on the same element is as far as I know impossible.
What you could do is a jQuery solution.
But is the fixed position really necessary? How about fixing the wrapper then just using relative on the other document to position it relative to the wrapper?
That should solve it.
You could use something like this :
HTML
<div id="wrapper">
<div id="fixed"></div>
</div>
CSS
#wrapper {
width: 400px;
height: 600px;
margin: 0 auto;
}
#fixed {
width: 40px;
height: 100px;
position: fixed;
top: 0;
margin-left: 400px;
}
Simple jsfiddle : http://jsfiddle.net/MXgT9/

Why is my position absolute child placed relative to the browser window instead of its position relative parent?

I have these two divs, one inside another, and I have the styles defined. The encapsulating one is relative and the child is absolute.
Isn't the child supposed to be positioned according to the left top corner of the outer div, #RightSection?
Instead, it's doing it according to the browser window, any leads?
<div id="RightSection">
<div id="Panels">
</div>
</div>
#RightSection
{
position: relative;
}
#Panels
{
position: absolute;
background-color: Blue;
width: 100px;
height: 100px;
z-index: 9000;
}
I have also found that if I do not declare the top and left css parameters for absolutely positioned elements it seems to ignore a parent above it and just jump to the body of the page.
Try just giving it top and left parameters, see if it helps,
#Panels
{
position: absolute;
top: 0;
left: 0;
background-color: Blue;
width: 100px;
height: 100px;
z-index: 9000;
}
It should look just fine once you add in those default parameters.
Absolute positioning inside of relative positioned elements is supposed to do what you describe, but it's not always supported behaviour. What browser are you use and what DTD are you serving?
See http://www.brainjar.com/css/positioning/default4.asp for details. It also has a demo of the positioning so that you can verify it works or not in your browser.
I can confirm that this does not work in IE6. I can't vouch for other browsers while I'm at work, though. Brief searching online leads me to believe that this problem exists in IE7 too, and would conceivably be an issue in IE8 as long as it's rendering in IE7 mode.

Absolute positioned child div expands to fit the parent?

Is there anyway for an absolute positioned child to expand to fill its relative positioned parent? (The height of parent is not fixed)
Here is what i did and it is working fine with Firefox and IE7 but not IE6. :(
<div id="parent">
<div id="child1"></div>
</div>
#parent { position: relative; width: 200px; height:100%; background:red }
#child1 { position: absolute; top: 0; left: 200px; height: 100%; background:blue }
That's easy. The trick is setting top: 0px and bottom: 0px at the same time
Here's the working code
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
#parent {
display: block;
background-color: #ff0;
border: 1px solid #f00;
position: relative;
width: 200px;
height: 100%;
}
#child1 {
background-color: #f00;
display: block;
border: 1px solid #ff0;
position: absolute;
left: 200px;
top: 0px;
bottom: 0px;
}
Check out a working example here http://jsfiddle.net/Qexhh/
If I remember correctly there is a bug with how IE6 handles div height. It will only create the div to the height needed to contain the content within it when height is set to 100%. I would recommend two approaches:
Don't worry about supporting IE6 as it is a dead browser anyway
If that doesn't work, use something like jQuery to get the height of the parent div and then set the child div to that height.
fake it by setting the backgrounds to be the same colour so no-one notices the difference
You can achieve this with setting both the top and bottom attributes of the child.
See how this is done
At the bottom of that article, there is a link to Dean Edwards' IE7 (and IE8) js library that you should include for IE6 visitors. It is a JS library that actually MAKES IE6 behave like IE7 (or 8) when you include it. Sweet!
Dean Edwars' IE7 and 8 JS libraries
As far as I know, there is no way of expanding a parent element around an absolutely positioned child element. By making the child element absolutely positioned your are removing it from the regular flow of page items.
I recently built a 2-column website where the right column was absolutely positioned but the left column was not. If the left column had less content and a smaller height than the right column, the page would cut off the right column since it was absolutely positioned.
In order to resolve this, I had to determine if the height of the right column was greater than the height of the left column and if so set the height of the parent div height to the greater of the two.
Here is my jQuery solution. I'm not much of a coder so feel free to tweak this:
jQuery(function(){
var rightColHeight = jQuery('div.right_column').height();
var leftColHeight = jQuery('div.left_column').height();
if (rightColHeight > leftColHeight){
jQuery('.content_wrap').height(rightColHeight+'px');
}
});

header overlapping the content

I have placed an absolutely positioned element (header) after relatively positioned element (body content). Due to some reason and this works fine in all the browsers except IE8.
The header is overlapping the content element with not positioned at its absolute position.
The css rules I have used:
#bodyContent{
clear: both;
display: table;
width: 920px;
margin-top: 173px;
_margin-top: 178px;
position: relative;
}
#headerContainer {
position: absolute;
top: 0px;
left:0px;
}
The header part is rendering from the content element postition with space in its position.
Is this the bug in IE8? Can anyone help me sort out this issue?
This sounds like an old IE7 bug.. can you place an element between them? That fixed it for me.
I've also had similar problems. I used the float command which solved the issue. Try float: left; in #headerContainer

Resources