Ok this is the div structure.
<div class="DivParent">
<a href="#">
<div class="DivWhichNeedToBeVerticallyAligned"></div>
</a>
</div>
DivParent has fixed width and height values but DivWhichNeedToBeVerticallyAligned does not have fixed height values.
If you make DivParent display:table-cell; you can vertically align DivWhichNeedToBeVerticallyAligned but i don't want to use that feature since it causes some mess.
A href tag link should be same size with the divParent i mean whole divparent has to be clickable. like display:block.
So are there any CSS way of vertically aligning or lightweight jquery solution would also help.
Thank you.
Here jsfiddle : http://jsfiddle.net/XHK2Z/
*
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 center a div vertically on a page, you can use the CSS position property, top property, and transform property. Start by setting the position of the div to absolute so that it's taken out of the normal document flow. Then set the top property to 50%.
To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.
You can use an extra helper to achieve vertical alignment in a block with fixed height.
Look at this: http://jsfiddle.net/kizu/7Fewx/
There you must have a helper near a block you want to align with:
.DivHelper {
display: inline-block;
vertical-align: middle;
height:100%;
}
And add display: inline-block; vertical-align: middle;
to .DivWhichNeedToBeVerticallyAligned
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