0

i think i'm doing something wrong. i mean, I'm trying to make a function to center one divs depending screen width.

cabecera is the div i'm trying to center using left position

my code start through this thinking:

mw ---> minimal width of the div

mg0 --> left margin + right margin ( the same value for both )

$(window).width = mg0 + mw = m + m + mw

this is my code.

function calc_margen() {
  var mw = 1000;
  var mpw = $(window).width();
  var mg0 = mpw - mw;
  var m = mg0 / 2;
  $('#cabecera').left( m );
  $('#pie').left ( m );
};
Community
  • 1
  • 1
7thkernel
  • 81
  • 7

1 Answers1

2

CSS:

#cabecera {
    width: 1000px;
    margin: 0 auto;
}

Or in jQuery:

$('#cabecera').css({width: 1000, margin: '0 auto'});
GManz
  • 1,548
  • 2
  • 21
  • 42
  • This is only for centering on the left and right as your question mentioned, if you are looking for center top, have a look at Garrett Vlieger's link in your question. – GManz Jan 02 '12 at 19:36