首页 > 其他 > 详细

元素居中显示

时间:2015-10-31 15:42:36      阅读:185      评论:0      收藏:0      [点我收藏+]

1.水平居中

.className{
    margin:0 auto;
    width:200px;
    height:200px;
}

 

2.垂直水平居中

 

.className{
    width:300px;
    height:200px;
    position:absolute;
    left:50%;
    top:50%;
    margin:-100px 0 0 -150px;
}

3.jquery实现水平垂直居中

$(window).resize(function(){

    $(‘.className‘).css({
        position:‘absolute‘,
        left: ($(window).width() - $(‘.className‘).outerWidth())/2,
        top: ($(window).height() - $(‘.className‘).outerHeight())/2
    });

});

// To initially run the function:
$(window).resize();

 

元素居中显示

原文:http://www.cnblogs.com/cyhj/p/4925585.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!