Reputation: 1272
Sorry for the weak title.
I have some jQuery that is going pretty well, however, I guess I don't know some of the basics. I want to write -wt/2px as the left margin but I don't understand how it's breaking out between string and number - any help?
Here is what we came up with after the answer / (we were over-riding our own css was just one of the problems CODEPEN
jQuery
$(document).ready(function(){
var innerH = $('.v-align'),
ht = innerH.height();
var innerW = $('.h-align'),
wt = innerW.width();
innerH.css({
'position':'absolute',
'top':'50%',
'margin':-ht/2+'px 0 0 0'
});
innerW.css({
'position':'absolute',
'left':'50%',
// ?
'margin': '0 0 0 '+(-wt/2)+'px'
});
});
Upvotes: 1
Views: 62
Reputation: 16726
use parens when in doubt:
innerH.css({
'position':'absolute',
'top':'50%',
'margin': (-ht/2)+'px 0 0 0'
});
innerW.css({
'position':'absolute',
'left':'50%',
'margin': '0 0 0 '+(-wt/2)+'px'
});
Upvotes: 1