I created a plugin to bottom-align a element. In it's simplest form I did this:
- Get height of outerElement (DIV)
- Get height of current element
- result = outerHeight - height of current element
- sett CSS attribute 'top' = result.
And it works... in Firefox and IE8, but not in Opera or Google Chrome.
I'm guessing it has to do with borders, padding and margin. So what do I have to do in order to make it work cross-browser?
UPDATE
Code has been revised and is working now.
(function($){
$.fn.alignBottom = function()
{
var defaults = {
outerHight: 0,
elementHeight: 0
};
var options = $.extend(defaults, options);
var bpHeight = 0; // Border + padding
return this.each(function()
{
options.outerHight = $(this).parent().outerHeight();
bpHeight = options.outerHight - $(this).parent().height();
options.elementHeight = $(this).outerHeight(true) + bpHeight;
$(this).css({'position':'relative','top':options.outerHight-(options.elementHeight)+'px'});
});
};
})(jQuery);
The HTML could look something like this:
div class="myOuterDiv">
<div class="floatLeft"> Variable content here </div>
<img class="bottomAlign floatRight" src="" /> </div>
</div>
and applying my jQuery plugin:
jQuery(".bottomAlign").alignBottom();