本文介绍了在垂直和水平方向将第二个弹性项目一分为二的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否有人指出我如何像下图所示那样垂直和水平拆分第二个伸缩项目?
Can please someone point me out how can I split out second flex item vertically and horizontally like I have in image below ?
我设法将一个大盒子切成两半,但未能使第二个弹性物品也一样.这就是我现在拥有的-> https://jsfiddle.net/paveu/8c9Ls5s8/
I managed to split in half one big box but I failed making it the same for second flex item.This is what I have right now -> 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;
}
}
推荐答案
请尝试告诉我我的答案是否有问题
Try this tell me if there is a problem in my answer
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;
}
}
输出:
这篇关于在垂直和水平方向将第二个弹性项目一分为二的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!