Flex Box出界?

时间:2016-05-02 17:30:16

标签: html css css3 flexbox

您好我一直在尝试在CSS中创建一个弹性框,如enter image description here

下面的图像

但我遇到的问题看起来像这张图片enter image description here

似乎div 3号推送下来的所有东西都是代码

#flexcontainer
{
width: 500px;
height: 210px;
border: 3px solid black;
display: flex;
flex-wrap: wrap;
padding: 5px;

}

.flexitem
{
background: yellow;
width : 150px;
text-align: center;
height: 100px;
line-height: 100px;
margin: 2px;
}

.two
{
width : 200px;
}
.three
{
width : 120px;
height: 100%;
}

我还尝试使用align-self属性并将其设置为延伸到.three但它也不起作用。这是html代码

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>
            Project Name
        </title>

    <link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
   <div id="flexcontainer">
    <div class="flexitem one">1</div> 
    <div class="flexitem two">2</div> 
    <div class="flexitem three">3</div> 
    <div class="flexitem four">4</div> 
    <div class="flexitem four">5</div> 
   </div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

实际上你可以包装flex ,然后重新排序子项:

&#13;
&#13;
#flexcontainer {
  width: 500px;
  height: 210px;
  border: 3px solid black;
  display: flex;
  flex-flow: column wrap;
  padding: 5px;
}

.flexitem {
  background: yellow;
  width: 150px;
  text-align: center;
  height: 100px;
  line-height: 100px;
  margin: 2px;
}

.two {
  width: 200px;
  order: 3;
}

.three {
  width: 120px;
  height: 100%;
  order: 5;
}

.five { order: 4; }
&#13;
<div id="flexcontainer">
  <div class="flexitem one">1</div>
  <div class="flexitem two">2</div>
  <div class="flexitem three">3</div>
  <div class="flexitem four">4</div>
  <div class="flexitem five">5</div>
</div>
&#13;
&#13;
&#13;

jsFiddle:https://jsfiddle.net/azizn/12xkrtp4/