div居中

    技术2025-06-15  24

    div绝对定位水平垂直居中(margin:auto实现绝对定位元素的居中)

    div{ width: 500px; height: 500px; background: red; position:absolute; left:0; top: 0; bottom: 0; right: 0; margin: auto; }

    div绝对定位水平垂直居中(margin 负间距)

    div{ width:200px; height: 200px; background:red; position: absolute; left:50%; top:50%; margin-left:-100px; margin-top:-100px; }
    Processed: 0.013, SQL: 9