gpt4 book ai didi

html - 将第二个 flex 元素垂直和水平分成两半

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:38 24 4
gpt4 key购买 nike

谁能告诉我如何像下图那样垂直和水平拆分第二个 flex 元素?

我设法把一个大盒子分成两半,但我没能把它和第二个 flex 元素做成一样。这就是我现在拥有的 -> https://jsfiddle.net/paveu/8c9Ls5s8/

谢谢,

HTML

<div class="desktop">
<div class="yellow">lorem</div>
<div class="orange">lorem</div>
<div class="purple">lorem</div>
<div class="green">lorem</div>
</div>

CSS

* {
box-sizing: border-box;
}
main,
div {
display: flex;
padding: 1rem;
}

.desktop {
flex-direction: column;
flex-wrap: wrap;
height: 400px;
width: 100%;
align-items: center;
justify-content: center;
align-content: stretch;

}

.desktop > div {
flex: 1;
}

div.orange {
background-color: #FFAD77;
width: 30%;
flex: 0 0 70%;
margin-left: 10px;
}

div.yellow {
flex: 0 0 100%;
width: 70%;
background-color: #FFE377;
}

div.purple {
width: 30%;
margin-left: 10px;

background-color: #FF77C8;
}

@media(max-width: 480px) {
.desktop > div {
flex: 1;
width: 100%;
margin: 0 auto;
}
div.orange {
order: -1;
flex: 2;
}
div.yellow {
flex: 5;
}
div.purple {
flex: 1;
}
}

End result for flexbox

最佳答案

试试这个告诉我我的答案是否有问题

html:

<div class="desktop">
<div class="yellow">lorem</div>
<div class="orange">lorem</div>
<div class="purple">lorem</div>
<div class="green">lorem</div>

</div>

CSS:

* {
box-sizing: border-box;
}
main,
div {
display: flex;
padding: 1rem;
}

.desktop {
flex-direction: column;
flex-wrap: wrap;
height: 400px;
width: 100%;
}

div {
flex: 1;
}

div.orange {
background-color: #FFAD77;
width: 30%;
flex: 0 0 50%;
}

div.yellow {
flex: 0 0 100%;
width: 40%;
background-color: #FFE377;
}

div.purple {
flex: 0 0 50%;

width: 30%;
background-color: #FF77C8;
}
div.green{
background-color: green;
width:30%;
}

@media(max-width: 480px) {
.desktop div {
flex: 1;
width: 100%;
}
div[orange] {
order: -1;
flex: 2;
}
div[yellow] {
flex: 5;
}
div[purple] {
flex: 1;
}
div[purple] {
flex: 6;
}
}

输出: enter image description here

关于html - 将第二个 flex 元素垂直和水平分成两半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com