I have something like this:
<tr>
<td>
<div class="blue">...</div>
<div class="yellow">...</div>
</td>
<td>
<div class="blue">...</div>
<div class="yellow">...</div>
</td>
</tr>
Here's a example of my current HTML: http://jsfiddle.net/DcRmu/2/
Inside a <tr>
, all <td>
s have the same height. I want the yellow <div>
s inside those <td>
s to align vertically along the bottom of <td>
; and the blue <div>
s to align vertically along the top of <td>
. I tried to set vertical-align
to bottom
and it didn't work.
Thanks!
For this to work, you need to have a parent container with the display: table; property, and inside that container you will have the number of columns you want to have centered, with the display: table-cell; (and vertical-align: middle; ) property.
Vertically centering div items inside another div Just set the container to display:table and then the inner items to display:table-cell . Set a height on the container, and then set vertical-align:middle on the inner items.
To get them centered along a line, you'd use vertical-align: middle; . Although note that it centers the text according to its tallest ascender and deepest descender. Each element lines up according to the line you've set, which doesn't change from element to element.
vertical-align:bottom;
should work
Example: http://jsfiddle.net/jasongennaro/DcRmu/
EDIT
As per the new fiddle
You just need to place vertical-align:bottom;
on the td
not on the div
I updated your fiddle: http://jsfiddle.net/jasongennaro/DcRmu/7/
EDIT 2
I reread the question again and I saw the change
I want the yellow
<div>
s inside those<td>
s to align vertically along the bottom of<td>
; and the blue<div>
s to align vertically along the top of<td>
To do this, you need to
vertical-align
to top
on the td
div
sdiv
a margin
equal to the height of the cell minus the sum of the div
heights. In this case, 200px - (50px + 50px) = 100px.New CSS
tr td{
width:200px;
height:200px;
background:red;
vertical-align:top;
}
div.blue{
width:50px;
height:50px;
background:blue;
float:left;
}
div.yellow{
width:50px;
height:50px;
background:yellow;
float:left;
clear:both;
margin-top:100px;
}
Working example: http://jsfiddle.net/jasongennaro/DcRmu/9/
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