是否可以在不使用绝对位置的情况下进行以下布局

时间:2019-02-14 05:23:57

标签: html css flexbox css-position

我想避免HTML中的任何更改,因为这可能导致其他布局和设计的回归。由于我们在所有设计和布局中使用相同的模板。

需要在不使用.content2绝对位置的情况下实现以下布局。并且content2content3的高度应该相等。

.wrapper {
  display: flex;
}

.content {
  background: red;
}

.content2 {
  background: green;
}

.content3 {
  background: yellow;
}

.newLayout {
  position: relative;
}

.newLayout .content2 {
  position: absolute;
  right: 0;
  width: 92px;
  padding: 2px 10px;
}

.newLayout .content3 {
  white-space: nowrap;
  margin-top: 20px;
  padding: 10px;
}
<div class="wrapper newLayout">
  <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentia</div>
  <div class="content2">Content Two</div>
  <div class="content3">Content Three</div>
</div>

3 个答案:

答案 0 :(得分:1)

使用flexbox,您需要具有嵌套的弹性框才能具有此布局。像这样的2D布局将是CSS grids理想案例-请参见下面的演示:

.wrapper {
  display: grid;
  grid-template-areas: "one two" "one three";    
}

.content {
  background: red;
  grid-area: one;
}

.content2 {
  grid-area: two;
  background: green;
}

.content3 {
  grid-area: three;
  background: yellow;
}
<div class="wrapper">
  <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentia</div>
  <div class="content2">Content Two</div>
  <div class="content3">Content Three</div>
</div>

答案 1 :(得分:0)

尝试这个小提琴Fiddle here

.wrapper {
display: flex;
}
.leftBox{
background:red
}
.leftBox, .rightBox{display:flex;flex-flow:column;}
.contentTwo, .contentThree{height:50%}
.contentTwo{background:green;}
.contentThree{background:yellow;}

答案 2 :(得分:0)

.wrapper {
  display: grid;
  grid-template-columns: 1fr, 92px;
  grid-template-rows: 1fr, 1fr;
}

.content {
  grid-area: 1/1/3/2;
  background: red;
}

.content2 {
  grid-area: 1/2/2/3;
  background: green;
}

.content3 {
  grid-area: 2/2/3/3;
  background: yellow;
}
<div class="wrapper">
  <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentia</div>
  <div class="content2">Content Two</div>
  <div class="content3">Content Three</div>
</div>