guangqiang 发表于 2013-2-7 17:27:55

用css或jquery方式 使div 水平、竖直均居中

<div style="font-size: 14px;" class="iteye-blog-content-contain">http://dl.iteye.com/upload/attachment/0079/3397/fb498a36-dead-31e3-b08a-56f934919156.png
 
.className{width:270px;height:150px;position:absolute;left:50%;top:50%;margin:-75px 0 0 -135px;} 
jquery方法$(document).ready(function(){    $(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();}); 
页: [1]
查看完整版本: 用css或jquery方式 使div 水平、竖直均居中