为弹性商品设置最大宽度?

kno*_*ose 5 html css css3 flexbox

我正在尝试在我的网站上创建一个过滤器部分,所有内容都是动态生成的(因此我无法为其添加额外的父对象),并且我们的样式指南使用flex项目创建了它们。我想在很大程度上保留此功能。

我希望我的3个flex项目具有a max-width并向左浮动,而在整个容器中将非flex项目向右浮动,设置为如下所示的最大宽度1080px

Option 1    Option 2    Option 3                                    Non-flex Item
Run Code Online (Sandbox Code Playgroud)

我试过设置flex-align值并遵循此答案,但这似乎并不起作用。

截至目前,这是我正在使用的代码:

的HTML

<ul class="container">
  <li class="child">One</li>
  <li class="child">Three</li>
  <li class="child">Three</li>
  <div class="non-flex">
   I'm not a flex item
  </div>
</ul>
Run Code Online (Sandbox Code Playgroud)

的CSS

.container{
      display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
        -webkit-box-pack: justify;
        -ms-flex-pack: justify;
        justify-content: space-between;
        position: relative;
            max-width: 1080px;
        margin: 0 auto;
        padding: 0 20px;
        box-sizing: content-box;
    }

    .child{
          display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
        -webkit-box-pack: justify;
        -ms-flex-pack: justify;
        justify-content: space-between;
        position: relative;
    }
Run Code Online (Sandbox Code Playgroud)

我还制作了一个小提琴供大家玩耍。

Joh*_*nes 5

我会申请一个widthmin-width.child项目(或左创建它们之间的距离/右填充),并margin-left: auto在最后一个项目,其移动是正确的,独立于其它:

https://jsfiddle.net/6vwny6bz/2/

.container {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: content-box;
}

.child {
  list-style: none;
  min-width: 80px;
  padding: 10px 0;
}

.non-flex {
  margin-left: auto;
  padding: 10px 0;
}
Run Code Online (Sandbox Code Playgroud)
<ul class="container">
  <li class="child">One</li>
  <li class="child">Three</li>
  <li class="child">Three</li>
  <div class="non-flex">
    I'm not a flex item
  </div>
</ul>
Run Code Online (Sandbox Code Playgroud)