flexbox layout with two items on the left and one

2019-09-13 04:48发布

I am trying to achieve the following layout with flexbox.

┌─┬─────┐
│A│     │
├─┤  C  │ 
│B│     │
└─┴─────┘

Is it possible to do so without wrapping A and B into a wrapper?

2条回答
做自己的国王
2楼-- · 2019-09-13 05:18

Yes, it's possible. Take in account that in this example the main container has a fixed width and height.

#container{
  height: 200px;
  width: 300px;
  display: flex;
  flex-flow: column wrap;
}

#container, #A, #B, #C{
  box-sizing: border-box;
  border: 1px solid black;
}

#A{
  height: 50%;
  width: 100px;
}

#B{
  height: 50%;
  width: 100px;
}

#C{
  height: 100%;
  width: 200px;
}
<div id="container">
  <div id="A">A</div>
  <div id="B">B</div>
  <div id="C">C</div>
</div>

查看更多
霸刀☆藐视天下
3楼-- · 2019-09-13 05:21

unfortunately, there is no fixed height, so I ended up with doing things old way — via tables, like this

HTML:

<div id="container">
   <div id="A">A<br>AAA<br>BBB</div>
   <div id="B">B</div>
   <div id="C">C</div> 
</div>

CSS:

#container {
   width: 100%;
   outline: 1px solid black;
   display: table;
}

#A,#B,#C {
   outline: 1px solid crimson;
}

#A,#B {
  width: 100%;
}

#C {
   display: table-cell;
   vertical-align: middle;
   width: 50%;
}
查看更多
登录 后发表回答