Split in half vertically and horizontally second flex item

二次信任 提交于 2019-12-25 02:28:12

问题


Can please someone point me out how can I split out second flex item vertically and horizontally like I have in image below ?

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/

Thanks,

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;
  }
}


回答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;
  }
}

output:



来源:https://stackoverflow.com/questions/49550792/split-in-half-vertically-and-horizontally-second-flex-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!