Center DIV via jQuery
Posted
by tony noriega
on Stack Overflow
See other posts from Stack Overflow
or by tony noriega
Published on 2010-03-08T17:16:28Z
Indexed on
2010/03/08
17:21 UTC
Read the original article
Hit count: 267
I have a footer that is fixed to the bottom of the viewport. I am using jQuery toggle to open a comment card for users to comment and submit:
$('a#footer-comment').click(function() {
$("#comment-card").toggle(300); return false;
$('#comment-card').show({ position:);
});
$('a#footer-comment-hide').click(function() { $("#comment-card").toggle(300); return false;
$('#comment-card').hide(); });
naturally if i dont add any CSS selectors to #comment-card it shows up UNDER the footer, and out of sight.
So i added: {position:absolute; bottom:30px; left:auto;} 30px so it shows up above the footer which is 30px high.
Problem is, i can not get this to center in the viewport... if i use pixels, depending on the resolution, it is either too far left or right... how do i center this in the viewport?
© Stack Overflow or respective owner