css - 在绝对定位的情况下怎么让div居中呢?
怪我咯
怪我咯 2017-04-17 13:43:56
[HTML讨论组]


    
    


怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(4)
迷茫

设置left值吧

PHP中文网
#p2 {
    width: 50px;
    height: 50px;
    background-color: red;
    margin: 0 auto;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -25px;
    margin-top: -25px;
}
阿神
#p2{
    width: 50px;
    height: 50px;
    background-color: red;
    margin:auto;
    position: absolute;
    top:0;
    bottom:0;
    left:0;
    right:0;
    }
ringa_lee

不会用搜索?在社区搜一搜就有答案,何必重复这么多问题。

@_qunshan_

@_qunshan_的答案

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号