I am using a div with 2 elements inside and I want to position my 1st element to be vertically aligned top and 2nd element to the bottom of the div. The div is the right portion of my page and equal to the height of my main content.
#right {
float:right;
width: 19%;
background:#FF3300;
margin-left:2px;
padding-bottom: 100%;
margin-bottom: -100%;
}
#right .top {
display:block;
background-color:#CCCCCC;
}
#right .bottom {
bottom:0px;
display:block;
background-color:#FFCCFF;
height:60px;
}
HTML:
<div id="right">
<span class="top">Top element</span>
<span class="bottom"><img src="images/logo_footer1.gif" width="57" height="57" align="left" class="img"> <img src="images/logo_footer2.gif" width="57" height="57" align="right" class="img"></span>
</div>
I want the right div to be like this: alt text http://christianruado.comuf.com/element.png
position : absolute Inside Other Positioned ElementsThe inner div element has position set to absolute and top to 0px and right to 0px . This places the inner div at the top right corner inside its parent element (because the parent element has position: relative set).
Absolute In position: relative , the element is positioned relative to itself. However, an absolutely positioned element is relative to its parent. An element with position: absolute is removed from the normal document flow. It is positioned automatically to the starting point (top-left corner) of its parent element.
If you specify position: relative
for #right
, and then position: absolute
for the two internal elements, you should be able to use top/left/bottom/right attributes to achieve the effect you want.
Try this.
#right {
position:relative; <-- add this
float:right;
width: 19%;
background:#FF3300;
margin-left:2px;
padding-bottom: 100%;
margin-bottom: -100%;
}
}
#right .top {
position:absolute; <-- add this
top: 0px; <-- and this
display:block;
background-color:#CCCCCC;
}
#right .bottom {
position:absolute: <-- add this.
bottom:0px;
display:block;
background-color:#FFCCFF;
height:60px;
}
Adding position:relative;
to the parent and position:absolute;
with top
and bottom
will tell your spans that they're meant to be positioned absolutely within your parent and force them to stick to the top and bottom of your div.
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