我想将文本(foo 链接)放置在页脚元素的右侧。
我需要页脚显示保持 flex
。
但是当我将它设置为 flex
时,float:right
不再适用于 span。
<footer style="display: flex;">
<span style="text-align: right;float: right;">
<a>foo link</a>
</span>
</footer>
最佳答案
float
属性在 flex 容器中被忽略。
来自 flexbox 规范:
3. Flex Containers: the
flex
andinline-flex
display valuesA flex container establishes a new flex formatting context for its contents. This is the same as establishing a block formatting context, except that flex layout is used instead of block layout.
For example, floats do not intrude into the flex container, and the flex container’s margins do not collapse with the margins of its contents.
float
andclear
do not create floating or clearance of flex item, and do not take it out-of-flow.
相反,只需使用 flex 属性:
footer {
display: flex;
justify-content: flex-end;
}
<footer>
<span>
<a>foo link</a>
</span>
</footer>
如果页脚中有更多元素,并且需要其他对齐选项,那么这里有两个指南:
关于html - float 在 flex 容器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194630/