Reputation: 428
I am having some html like below ..
<div id="dynamicheight"></div>
<div id="one"></div>
<div id="two"></div>
<div id="target"></div>
if u see the html "dynamicheight" div will get height dynamically on pageload and i want the "target" div to stay always at the bottom of "dynamicheight" div(as per its height)
note: there are couple other div's in between as shown in html
i am trying to do below css
#dynamicheight{
position: relative;
}
#target{
position: absolute;
bottom: 0;
}
but its not working any work around plz...........
Upvotes: 0
Views: 6074
Reputation: 99464
Please note that #dynamicheight
and #target
elements are siblings.
They'll be rendered one after another in document normal flow.
You probably need to manipulate DOM, to achieve this (without removing #target
element from document flow by using absolute
positioning):
jQuery(function($){
$('#target').insertAfter('#dynamicheight');
});
But, in some cases, it might be better to move the second element into the first one:
jQuery(function($){
$('#target').appendTo('#dynamicheight');
});
In this case, you need to use position
property to keep the second element at the bottom of the first one:
#dynamicheight {
position: relative;
height: 400px; /* Just as demo */
}
#target {
position: absolute;
bottom: 0;
width: 100%; /* Optional */
}
Upvotes: 0
Reputation: 8981
Like this
you have used in html id
or in css
you have defined class
so please change if in css
remove
class
and write id
html
<div id="dynamicheight"></div>
<div id="one"></div>
<div id="two"></div>
<div id="target"></div>
css
#dynamicheight{
position: relative;
}
#target{
position: absolute;
bottom: 0;
}
Upvotes: 0
Reputation: 269
you can change the markup to be
<div id="dynamicheight" class='dynamicheight'></div>
<div id="one"></div>
<div id="two"></div>
<div id="target" class='target'></div>
or change css to be
#dynamicheight{
position: relative;
}
#target{
position: absolute;
bottom: 0;
}
Upvotes: 0
Reputation: 32581
The selector is incorrect. You are applying to dynamicheight class. Change .
to #
#dynamicheight{
position: relative;
}
#target{
position: absolute;
bottom: 0;
}
Upvotes: 2
Reputation: 1492
If you are writing CSS for element with certain ID, you need to write #target, not .target.
Upvotes: 1