1

ANSWER UPDATED

form my research to get AUTO margin-top in all browser I'm use this code

var bookContainer   = $('#book-container');

bookContainer.offset().top

I don't know what wrong with Firefox and Safari

It alert 0px which not correct but Chrome and IE can perform Correct

with this same code. I want to ask do you know what happen or somethings??

JS

var bookContainer   = $('#book-container');

alert(bookContainer.css('margin-top'))

CSS

#book-container{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    width: 80%;
    max-width: 830px;
    max-height: 520px;

    /*max-width: 748px;*/
    /*max-height: 469px;*/
}
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96

1 Answers1

1

try this it worked for me

var leftMarginValue= $('.container').offset().left;

Since you are using margin auto for a div. you will get similar margin on the both side of element.

Shuhad zaman
  • 3,156
  • 32
  • 32