【问题标题】:Flex Box out of borders? [duplicate]Flex Box 越界了? [复制]
【发布时间】:2016-08-27 13:22:21
【问题描述】:

您好,我一直在尝试用 CSS 制作一个弹性框,如下图

但我有一个问题,看起来像这张图片

似乎 3 号 div 将这里的所有内容都推送到了代码

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

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    其实你可以把 flex columns 换行,然后对子元素重新排序:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 2023-02-02
      • 1970-01-01
      相关资源
      最近更新 更多