I am trying to stack two divs A and B.
Div A - will be scrollable but its height needs to be determined by the div underneath it, Div B so if the content in Div B changes, and it's height changes the height of Div A also changes.
Div B - needs to be aligned to the bottom of page on top of a absolute positioned footer. Its content needs to be aligned to the bottom.
I've tried using position relative and float by wrapping these divs in a wrapper, but the whole thing breaks when I try to keep the Div B aligned or positioned absolutely above the footer.
I've got a feeling this needs to go back to basics, any help would be greatly appreciated
thanks
Here's a basic example. I think I have correctly understood your requirement. This example has them appear to be stacked but in the HTML they are not actually stacked, they are nested. I wasn't sure if you could allow that in your solution but fingers crossed.
Example: http://jsfiddle.net/jyR2A/1/
CSS:
#divA {overflow-y:scroll;position:absolute;height:100%;top:-100%;background:green;width:100%;}
#divB {position:absolute;bottom:0;background:blue;width:100%;color:white;}
HTML:
<div id="divB">
<!-- Div A is nested so we can use divB's height -->
<div id="divA">
</div>
<!-- Div B content -->
<div id="divBinnerContent">
Line 1 <br />
Line 2 <br />
..Keep adding more lines to test how it works <br />
</div>
</div>
How it works:
divB is the parent element defining the height of divA. So if we set divB position relative or absolute and place divA inside then we can set divA's height to 100% to give it the height of parent element divB.
Now to position divA we make sure it has position:absolute and set top:-100% which will move it up the same distance as the height of its container divB. Position absolute not only allows us to position it correctly but it also removes it from affecting the height of its parent, divB.
And the content for divB I have made a nice container for it but it is not neccessary. Simply put it anywhere inside divB (but not inside divA) and it will be OK.
You can use the content to define the height,as I have, or use an absolute height set in CSS.
Hope this is what you were after.
Le-roy
I managed to achieve this with help from this question and fiddle.
Stack div elements in css vertically (with dynamic height)
http://jsfiddle.net/nCrEc/334/
Essentially the answer was giving my Div A a height without using the height parameter but instead using absolute positioning on top and bottom. Which meant changes to Div B changed the location of the Div A's bottom (oo er) which pushed the middle div up whenever another populates the bottom area.
<div class="con">
<div class="top"></div>
<div class="middle"></div>
<div class="bottom"></div>
</div>
then using this CSS
.con {
width:200px;
top:50px;
bottom:0;
left:0;
position:absolute;
background:#ff0;
}
.top {
width:200px;
height:20px;
position:absolute;
top:0;
left:0;
background:#f60;
}
.bottom {
width:200px;
height:50px;
position:absolute;
bottom:0;
left:0;
background:#f60;
}
.middle {
overflow-y:auto;
min-height:1px;
position:absolute;
bottom:50px;
top:20px;
left:0;
background:#06f;
}
Related
Is there any way to get width value in px which is in percentage and apply to that another element?
first of all take a look at my code
<div class="col-md-6 height-half">
.........
</div>
col-md-6 means its width is 50%;its not in pixel.And the added height-half means i want to apply max-height half of the width.
Can i do that only with css?
This portion is not important just for posting question
So i also can do some more works done with that.Such like height-one-fourth,height-one-third and something like that
I might be understanding incorrectly. But try using the :before pseudo element to dictate the height.
You already have the width taken care of with .col-md-6. So with using :before on .height-half you should be all set:
.height-half:before {
content:"";
display:block;
padding-top:50%;
}
This will make your div have a height equal to 50% of your width. The only caveat is that you will need to make a container div that is positioned absolutely inside of this div:
<div class="col-md-6 height-half">
<div class="container">
.........
</div>
</div>
So the CSS has to do this for all of the containers you want to use this way:
.container {
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
}
You also need to make all of your columns position:relative or some kind of position so that the container sees that it's being positioned absolutely to it's container.
Here's an example fiddle
I have a parent div, which contains two other Divs and I'm looking to animate the background-image of the parent div so that it constantly scrolls along the x-axis. The image is 3840px wide and the div is 100% of the browser (1920px). Essentially the image needs to repeatedly scroll whilst not impacting upon the child elements within the parent div, is this possible?
Here is my HTML
<div id="SliderBackground">
<div id="SliderBanner"></div>
<div id="SliderStaticImage"></div>
</div>
Here is my CSS
#SliderBackground
{
width:100%; /*1920px*/
height:500px;
background-image:url(Background.png);
z-index:-1;
position:absolute;
top:90px;
}
Thankyou in advance.
I have the following.
If u see, the "asdasdasd" text is not near the top of the div.
I have a div with two divs inside
<div id="widget">
<div id="header"> </div>
<div id="content"> </div>
</div>
The header div have a fixed height, and this background image.
If you see what is in red, that part of the background make me need the div to be bigger, but it moves the content div down.
I tried to pull it up using margin-bottom: -Ypx; but I think its a ugly fix. I can't find something that works for me.
somebody can help (:?
Yeah you can use the position:absolute to keep out the div header you need this properties:
#widget {
position:relative;
}
Make the parent relative, that way the position absolute of the header will be relative to this container
#header {
position:absolute;
top:0;
left:0;
}
Position absolute to the top ande left of his container
I am working on a layout that is placed into a wrapper with a fixed height and contains three inner containers.
The first container (header) should be placed on top within the wrapper and is flexible in it's height.
The second container (content) is flexible in it's height as well and need to overflow if the available space is not sufficient (overflow-y: auto).
The third container (footer) also has an unknown height and needs to be placed at the bottom of the wrapper at any time.
<div id="wrapper">
<div id="header">
<span>
some unknown content that is placed at the top of the wrapper
</span>
</div>
<div id="content">
<span>
some more unknown content and within here we want
to enable vertical scrolling if necessary
</span>
</div>
<div id="footer">
<span>
again unknown content that should be placed at the bottom of
the wrapper at any time
</span>
</div>
</div>
The options I have ruled out so far:
absolute positioning of the footer within the relative positioned wrapper: doesn't work in this case since we don't know the footer's height
flexbox model: not possible since I need to support IE8+
table: the content row doesn't overflow, the complete table would overflow and the footer would be positioned outside of the wrapper
table with the content td element's position set to relative and including a div element with position set to absolute (containing the actual content): seems to fix the overflow issue in most browsers, but e.g. in IE9 the content div (with height set to 100%) results in a height of 0
Is there any other option without using Javascript that might work here?
It took a while but I believe this is it, I adapted it from my answer to another question. The .inner div must have height:100% but anything inside it should be able to be modified however you want.
http://jsfiddle.net/Z4K7J/2/
.left {
border:1px solid orange;
width:200px;
height:300px;
display:table;
}
.top {
display:table-row;
}
.middle {
display:table-row;
height:100%;
}
.middle .inner {
background-color:red;
height:100%;
overflow-y:auto;
}
.bottom {
display:table-row;
}
I have two divs I want to place one inside the other. The parent div has height 100% and is x-scrollable (the content will overflow to the right).
The child div has a repeatable background image set through css.
I want to place it at the bottom of the parent div (above the scrollbar), like a footer but when the scroll is moved this div should stay still.
How can this be done?
Right now I have
.parent{
overflow-x:scroll;
overflow-y:hidden;
width:100%;
height:100%;
position:fixed; }
.child{
height:33px;
width:100%;
bottom:0;
left:0;
background-image:url(<image_path>);
background-repeat:repeat-x;
position:absolute;}
<div class="parent">
<div class="child">
</div>
</div>
The problem I'm having is that the child div moves when scrolling the parent div.
Thanks.
You don't really need the child div unless there's some other content there in addition to the background image. You could do it all in the parent div.
JSBin Demo -------> HERE
After your fiddle... an edit... Forget the background of the child div. Place the background image on the parent div. let the child div be transparent and contain the text.
Updated Fiddle --------> HERE