如何将弹性项目对齐?

Lov*_*ess 3 html css flexbox

我想把RED按钮放在右边,就像我过去使用花车一样

小提琴:http://jsfiddle.net/vb61r4uL/

.container {
    height: 100%;
    width: 100%;
    background-color: yellow;
    display: flex;
    align-items: center;
    justify-content: center;
}

ul, li {
    list-style: none;
    padding: 0px;
}

#list {
    width: 300px;
    background: grey;
}

.item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.destory-button {
    background:red;
    justify-content: flex-end;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<ul id="list">
    <li>
        <div class="item">
             <input type="checkbox">
            Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
    <li>
        <div class="item">
             <input type="checkbox">
            2nd Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
    <li>
        <div class="item">
             <input type="checkbox">
            3rd Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
</ul>   
</div>
Run Code Online (Sandbox Code Playgroud)

如何使按钮对齐?

Ric*_*ock 7

添加此样式:

.destory-button {
  margin-left: auto;
}
Run Code Online (Sandbox Code Playgroud)

参考:http: //www.w3.org/TR/css3-flexbox/#auto-margins

.container {
    height: 100%;
    width: 100%;
    background-color: yellow;
    display: flex;
    align-items: center;
    justify-content: center;
}

ul, li {
    list-style: none;
    padding: 0px;
}

#list {
    width: 300px;
    background: grey;
}

.item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.destory-button {
  background:red;
  justify-content: flex-end;
  margin-left: auto;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<ul id="list">
    <li>
        <div class="item">
             <input type="checkbox">
            Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
    <li>
        <div class="item">
             <input type="checkbox">
            2nd Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
    <li>
        <div class="item">
             <input type="checkbox">
            3rd Title
            <button class="destory-button">Destroy</button>           
        </div>        
    </li>
</ul>   
</div>
Run Code Online (Sandbox Code Playgroud)

  • @ManojKumar,`align-self:flex-end`适用于横轴(在本例中为垂直平面).对于主轴,你需要像'justify-self:flex-end`这样的东西,它不存在,但是`auto` margin是一个很好的替代品. (2认同)
  • 知道了谢谢.当"flex-direction"设置为"column"时,当横轴现在是水平面时,它可以工作.我想我在这里偶然发现了你的问题:http://stackoverflow.com/questions/32551291/in-css-flexbox-why-are-there-no-justify-items-and-justify-self-properties值得在这里添加为一条评论.*由于演示代码具有不同的属性,因此必须删除我的上述评论.*[**JSfiddle demo**](http://jsfiddle.net/Manojkr/ppv7h4fd/3/) (2认同)