jQuery Vertical Align

An easy way to vertical align elements with one line of code:


I've removed the parameters as it turns out if you pass in a negative offset using padding, IE6 throws an error and JavaScript fails to continue executing. If you get the following error in IE6 debugging, it may be due to passing in a negative value to a padding css attribute, or similar:

  • invalid argument jquery J[G]=K

It's fairly easy to structure your html to not require a vertical align offset so it's really not needed anyways. 

It also supports a couple of parameters: 

  • offset = the number of pixels to offset the vertical alignment 
  • usePadding = true/false. the default is false which uses a margin to align, if set to true, it uses padding 
$('.innerText').VerticalAlign({offset:-20, usePadding:true})

Get the source: (290.00 bytes)

Need an Umbraco Master?


Contact Simon Today!