我有一个
<div class="parent">
<div class="child" style="float:right"> Ignore parent? </div>
<div> another child </div>
</div>
父级有
.parent {
display: flex;
}
对于我的第一个子元素,我只想将项目向右浮动。
和我的其他div遵循父母设置的伸缩规则。
这有可能吗?
如果不是,我怎么做一个浮动:在flex的权利?
你不需要花车。事实上,它们是无用的,因为浮动在flexbox中被忽略了。
你也不需要CSS定位。
有几种可用的flex方法。在另一个答案中提到了汽车利润率。
这里还有另外两种选择:
使用justify-content: space between和order属性。
使用justify-content: space between和颠倒div的顺序。
.parent {
display: flex;
justify-content: space-between;
}
.parent:first-of-type > div:last-child { order: -1; }
p { background-color: #ddd;}
<p>Method 1: Use <code>justify-content: space-between</code> and <code>order-1</code></p>
<div class="parent">
<div class="child" style="float:right"> Ignore parent? </div>
<div>another child </div>
</div>
<hr>
<p>Method 2: Use <code>justify-content: space-between</code> and reverse the order of
divs in the mark-up</p>
<div class="parent">
<div>another child </div>
<div class="child" style="float:right"> Ignore parent? </div>
</div>