简体   繁体   English

CSS Flexbox - 多行/w flex-direction:列

[英]CSS Flexbox - Multiple rows /w flex-direction: column

Please see the design brief attached I'm trying to figure out how to align the Green colored box so that it equally equates to 25% of the height when viewed via my @media only screen and (max-width: 600px) query in my CSS.请参阅随附的设计简介我试图弄清楚如何对齐绿色框,以便在通过我的 @media only 屏幕和我CSS。 Along with an issue with the yellow blocks not aligning to the same height as the green colored box.以及黄色块未与绿色框对齐到相同高度的问题。

I cannot seem to arrange the content blocks in height order as seen on the design brief -> mobile view (right-side).我似乎无法按照设计简介 -> 移动视图(右侧)中所见的高度顺序排列内容块。

[design brief]: https://i.stack.imgur.com/rw8ib.jpg 【设计简介】: https://i.stack.imgur.com/rw8ib.jpg

//HTML// //HTML//

<div class="container">
<div class="red">
    <!-- <label>A</label> -->
</div>

<div class="yellow_green_wrapper">
    <div class="yellow"> <!-- <label>B</label> -->
        <div class='one'></div>
        <div class='two'></div>
        <div class='three'></div>
        <div class='four'></div>
    </div>
    
    <div class="green">
        <!-- <label>C</label> -->
    </div>
</div>


<div class="blue">
    <!-- <label>D</label> -->
</div>
    .container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    gap: 0.5rem;
    padding: 0.5rem;
}

@media only screen and (max-width: 600px) {
    .yellow_green_wrapper {
        flex-direction: column-reverse; 
    }

    .yellow.four {
        width: 100%;
    }
    .yellow  > div.two, .yellow  > div.three, .yellow  > div.four {
        width: 33%;
    }
}

.yellow_green_wrapper {
    display: flex;
    width: 100%;
    position: relative;
    flex-grow: 1;
}

.red , .blue, .green, .yellow {
    width: 100%;
    position: relative;
    flex-grow: 1;
}

.red label, .blue label, .green label, .yellow label{
    position: absolute;
    left: 50%;
    top: 50%;
}

.red {
    background-image: linear-gradient(rgba(122, 45, 45, 0.9),rgba(168, 77, 77, 0.9));
}

.blue {
    background-image: linear-gradient(rgba(31, 70, 177, 0.9),rgba(144, 172, 209, 0.9));
}

.green {
    background-image: linear-gradient(rgba(161, 241, 181, 0.9),rgba(101, 163, 114, 0.9));

}

.yellow {
    display: flex;
    flex-flow: row wrap;
}

.yellow, .green {
    height: 100%;
}

.yellow  > div {
    background-image: linear-gradient(rgba(248, 171, 6, 0.9),rgba(230, 181, 117, 0.9));
    flex-grow: 1;
    margin: 0.5rem;
}

.yellow  > div.one {
    width: 100%;
}

The layouts look suitable for using CSS grid.布局看起来适合使用 CSS 网格。 That way things are simplified as you don't need to individually define widths etc.这样事情就简化了,因为您不需要单独定义宽度等。

This snippet removed the grouping of yellow and green and uses the CSS grid-template-areas property to set up the various layouts.此代码段删除了黄色和绿色的分组,并使用 CSS grid-template-areas 属性来设置各种布局。

 .container { display: grid; grid-template-areas: 'AA' 'BC' 'D D'; rgrid-template-columns: 1fr 1fr; rgrid-template-rows: 1fr 1fr 1fr; width: 100vw; height: 100vh; gap: 0.5rem; padding: 0.5rem; }.red label, .blue label, .green label, .yellow label { position: absolute; left: 50%; top: 50%; }.red { grid-area: A; background-image: linear-gradient(rgba(122, 45, 45, 0.9), rgba(168, 77, 77, 0.9)); }.yellow { grid-area: B; display: grid; gap: 0.5rem; grid-template-areas: 'WWW' 'XY Z'; }.yellow>* { background: yellow; }.one { grid-area: W; }.two { grid-area: X; }.three { grid-area: Y; }.four { grid-area: Z; }.blue { background-image: linear-gradient(rgba(31, 70, 177, 0.9), rgba(144, 172, 209, 0.9)); grid-area: C; }.green { background-image: linear-gradient(rgba(161, 241, 181, 0.9), rgba(101, 163, 114, 0.9)); grid-area: D; } @media (max-width: 600px) {.container { grid-template-areas: 'A' 'C' 'B' 'D'; grid-template-columns: 1fr; grid-template-rows: 1fr 1fr 1.5fr 1fr; }.yellow { grid-template-areas: 'WW' 'XY' 'Z Z'; } }
 <div class="container"> <div class="red"> <!-- <label>A</label> --> </div> <div class="yellow"> <!-- <label>B</label> --> <div class='one'></div> <div class='two'></div> <div class='three'></div> <div class='four'></div> </div> <div class="green"> <!-- <label>C</label> --> </div> <div class="blue"> <!-- <label>D</label> --> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM