垂直和水平分成两半弹性项目

时间:2018-03-29 07:56:27

标签: html css css3 flexbox

请有人指出我如何能够像下面的图像一样纵向和横向拆分第二个弹性项目?

我设法分成了半个大盒子,但我没能在第二个弹性项目中使它变得相同。 这就是我现在所拥有的 - > 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

1 个答案:

答案 0 :(得分:1)

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

<强> 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