CSS3技巧:fit-content水平居中

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <ul>
            <li>導航</li>
            <li>導航</li>
            <li>導航</li>
            <li>導航</li>
            <li>導航</li>
        </ul>
    </div>
</body>
<style>
    * {
        margin: 0px;
        padding: 0px;
    }
    
    .box {
        width: 1200px;
        margin: 50px auto;
    }
    
    .box ul {
        margin: auto;
         width: -moz-fit-content;
         width: -webkit-fit-content;
         width: fit-content;
    }
    
    .box ul li {
        width: 100px;
        margin: 0 auto;
        float: left;
        list-style-type: none;
    }

</style>

</html>

 

目前這個屬性只支持Chrome和Firefox瀏覽器,下面是居中的代碼:html

width:-moz-fit-content;
width:-webkit-fit-content;web

相關文章
相關標籤/搜索