【居中】不定宽的水平居中 / 浮动元素的水平居中

浮动元素的水平居中

float-left的对象如何居中

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <style>
        *{margin:0;padding:0;}
        .wrap{clear:both;}
        .box{background:#ff0;}
        body {
            width: 100%;
            overflow: hidden;
        }
        .wrap {
            position: relative;
            left: 50%;
            float: left;
        }
        .box {
            position: relative;
            right: 50%;
            float: left;
        }
        .box1 {
            width: 300px;
        }
        .box2 {
            width: 600px;
        }
    </style>
    <div class="wrap">
        <div class="box box1">box1</div>
    </div>
    <div class="wrap">
        <div class="box box2">box2</div>
    </div>
</body>
</html>

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <style>
        *{margin:0;padding:0;}
        ul{list-style:none;}
        .box{background:#ff0;}

        .wrap {
            text-align: center;
        }
        .box {
            display: inline-block;
            *display: inline;
            *zoom: 1;
            text-align: left;
        }
        .box li {
            float: left;
        }
    </style>
    <div class="wrap">
        <ul class="box">
            <li>box</li>
            <li>box</li>
            <li>box</li>
        </ul>
    </div>
</body>
</html>
原文地址:https://www.cnblogs.com/jzm17173/p/2628224.html