【发布时间】:2016-01-21 13:37:42
【问题描述】:
我有一个包含 1 到 3 个项目的 div,我希望它们的行为如下:
-
三项:用
justify-content: space-between取整行+-----------+ | 1 | 2 | 3 | +-----------+ -
如果只有 1 项,则将其向右对齐。
+-----------+ | | 3 | +-----------+
这是我的代码:
.container {
display: flex;
width: 300px;
justify-content: space-between;
/* Styling only */
padding: 10px;
background: #ccc;
margin-bottom: 10px;
}
.container div {
/* Styling only */
background: white;
padding: 20px 40px;
width: 10px;
}
<div class="container">
<div>
1
</div>
<div>
2
</div>
<div>
3
</div>
</div>
<div class="container">
<div>
3
</div>
</div>
我找到了direction: rtl 的解决方案,但我希望有一个不那么老套的解决方案,我不想重新排序我的 dom。
有什么想法吗?
【问题讨论】:
-
方向:rtl 实际上不是 hack。