关于如何使 div 居中的问题
当 div 具有固定宽度(y px)时,我只使用 left: 50% 和 margin-left: -y/2 px;
但是我如何将具有宽度:100% 和固定最大宽度的 div 居中?IE
body_container
{
position: absolute;
margin: auto;
max-width: 1750px;
height: 100%;
width: 100%;
}
Try this jQuery to make a div center of the page:
<script>
    jQuery.fn.vh_center = function (absolute) {
        return this.each(function () {
            var t = jQuery(this);
            t.css({
                position:   absolute ? 'absolute' : 'fixed', 
                left:       '50%', 
                top:        '50%', 
            }).css({
                marginLeft: '-' + (t.outerWidth() / 2) + 'px', 
                marginTop:  '-' + (t.outerHeight() / 2) + 'px'
            });
            if (absolute) {
                t.css({
                    marginTop:  parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                    marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
                });
            }
        });
    };
    $(document).ready(function(){
                               $('#Your_div').vh_center();
                               });
</script>