gpt4 book ai didi

html - float 在 flex 容器中不起作用

转载 作者:技术小花猫 更新时间:2023-10-29 11:39:16 26 4
gpt4 key购买 nike

我想将文本(foo 链接)放置在页脚元素的右侧。

我需要页脚显示保持 flex

但是当我将它设置为 flex 时,float:right 不再适用于 span。

<footer style="display: flex;">
<span style="text-align: right;float: right;">
<a>foo link</a>
</span>
</footer>

https://jsfiddle.net/dhsgvxdx/

最佳答案

float 属性在 flex 容器中被忽略。

来自 flexbox 规范:

3. Flex Containers: the flex and inline-flex display values

A 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 and clear 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com