I have the following code used to solve this problem I had. It works in IE9/Chrome:
$(document).ready(function () {
var legendWidth = $('#titleInner').outerWidth();
var margin = 'calc((100% - ' + legendWidth + 'px) / 2)';
$('#titleInner').css('margin-left', margin);
$('#titleInner').css('margin-right', margin);
});
However, I would like to get rid of the CSS calc() function so that it works in IE7/8.
I had seen this question/answer using jQuery to do the calculations which seems like a good solution.
Problem is I can't get the syntax/chaining working.
Here is what I have tried:
$(document).ready(function () {
var legendWidth = $('#titleInner').outerWidth();
$('#titleInner').css('margin-left', '100%').css('margin-left', '-' + legendWidth + 'px').css('margin-left', '/2');
$('#titleInner').css('margin-right', '100%').css('margin-right', '-' + legendWidth + 'px').css('margin-right', '/2');
});
I have tried a few variations (removing the 'px', etc) but no luck. I also couldn't figure out how to add parens to scope the '/2' across multiple chain elements.
So, can anyone please help with the jQuery equivalent to var margin = 'calc((100% - ' + legendWidth + 'px) / 2)';
?