【问题标题】:How to make this layout? (Triple nested Div)如何制作这种布局? (三重嵌套 Div)
【发布时间】:2021-07-25 12:25:27
【问题描述】:

我在下面制作了一个我正在尝试创建的快速线框图。 我只是想将 childDiv 左侧的 25% 突出显示为绿色,将右侧的 65% 突出显示为红色。

我想建立正确的空间,让左 childInnerDiv 为绿色,右 childInnerDiv 为红色。但这似乎不起作用...

我正在尝试创建的内容:

我有什么:

JsFiddle:http://jsfiddle.net/8vhgq6k3/

HTML 代码

        <div class="ProjectsParentDiv">
            <div class="childDiv">
                Foo
                <div class="childInnerDiv left">

                </div>
                <div class="childInnerDiv right">
                    
                </div>
            </div>
            <div class="childDiv">
                Bar
            </div>
            <div class="childDiv">
                Baz
            </div>
        </div>

CSS 代码

.ProjectsParentDiv {
    // position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: max-width;
    height: 40%;
    border: 1px solid black;
}

.childDiv {
    display: flex;
    background-color: lightblue;
    width: 75%;
    height: 150px;
    margin: 5px auto;
}

.childInnerDiv {
    //trying to make the childInnerDiv to be 95% height & width. of the ChildDiv
    height: 95%;
    width: 95%;
}

.childInnerDiv.left {
    flex: 25; //25% of the left side is a div for image.
    background: green;
    border: 1px solid yellow;
}

.childInnerDiv.right {
    flex: 65; //65% of right side is a div for description
    background: red;
    border: 1px solid silver;
}

【问题讨论】:

    标签: html css sass flexbox


    【解决方案1】:

    你可以在下面做。

    .ProjectsParentDiv {
        // position: relative;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: max-width;
        height: 40%;
        border: 1px solid black;
    }
    
    .childDiv {
        align-items: center;
        display: flex;;
        justify-content: space-around;
        background-color: lightblue;
        width: 75%;
        height: 150px;
        margin: 5px auto;
    }
    
    .childInnerDiv {
        display: flex;
        height: 95%;
    }
    
    .childInnerDiv.left {
        width: 25%; 
        background-color: green;
        border: 1px solid yellow;
    }
    
    .childInnerDiv.right {
        width: 65%;
        background-color: red;
        border: 1px solid silver;
    }
    <div class="ProjectsParentDiv">
        <div class="childDiv">
            <div class="childInnerDiv left">
    
            </div>
            <div class="childInnerDiv right">
    
            </div>
        </div>
        <div class="childDiv">
            Bar
        </div>
        <div class="childDiv">
            Baz
        </div>
    </div>

    【讨论】:

    • 很好,谢谢:)!我还向 childDiv 和 childInnerDivs 添加了 Z-index,因为颜色由于某种原因被阻止了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2016-07-31
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多