flex布局和float布局混合使用导致的css失效问题 (上)

需求:两端对齐
《flex布局和float布局混合使用导致的css失效问题 (上)》

这个需求应该是比较容易的,使用flex布局就可以轻松完成。但是我贱啊,没办法。

<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>flex布局和float布局混用导致的布局混乱的原因</title>
    <link rel="stylesheet" type="text/css" href="index.css">
    <style>
        #root {
            width: 800px;
            height: 800px;
            position: relative;
            margin: auto;
        }

        .container {
            width: 100%;
            height: auto;
            border: 1px solid #ccc;

            /*水平布局*/
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .container > div {
            display: flex;
            flex-direction: row;
        }
           
        /*左按钮组左浮动,右按钮组右浮动*/
        .container > div:nth-child(1) {
            float: left;
        }

        .container > div:nth-child(2) {
            float: right;
        }

        .container > div > button {
            width: 80px;
            height: 40px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div id="root">
    <div class="container">
        <div>
            <button>search</button>
            <button>update</button>
        </div>
        <div>
            <button>cancel</button>
            <button>create</button>
        </div>
    </div>
</div>
<script>
</script>
</body>

</html>

没有采用 justify-content: space-between; 后果是预期中的左按钮组没有左浮动,右按钮组也没有右浮动。
《flex布局和float布局混合使用导致的css失效问题 (上)》
为什么会失效呢?这需要深入理解flex布局。这是我下一篇需要着重解决的问题。

    原文作者:洛神赋
    原文地址: https://segmentfault.com/a/1190000019831745
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞