SearchRecent postsThe Random ToolboxDrupal 7 Setting up variables for use in a template (preprocess and process functions) Rendering Drupal 7 fields (the right way) Linux Secure Copy (scp) command Restrict Free Shipping in Magento Quickbooks Text Connection Ticket Cross-Site Request Forgery (CSRF) jQuery Events: MouseOver / MouseOut vs. MouseEnter / MouseLeave Monthly archive
|
Vertically Align an Element with jQuery - Vertical Align an Anchor or Div//align text vertically var i = 1; // for debugging $('div.view-home-colored-circles div.view-content ul li a').each(function(){ var ah = $(this).height(); // insert the element/id/class to center within var ph = $(this).parents('li').height(); var mh = Math.ceil((ph-ah) / 2); // may choose to use margin-top - depends on your case $(this).css({'padding-top':mh}); // for debugging console.log('a position: ' + i + 'a height: ' + ah + 'li height:' + ph + 'padding-top: ' + mh); // increment counter to track styles applied to which element i++; }); |