【发布时间】:2015-02-18 04:07:29
【问题描述】:
我正在为我的网站创建一个标题,其中包含一个标题、导航链接列表和一个搜索表单。整个页面使用 flexbox 设置,因此:
HTML:
<div id="pagecontainer"> <!--the flex container-->
<header id="pageheader"><!--the header--><h1>...</h1><!--the heading-->
<nav><ul>...</ul></nav><!--the navigation-->
<form>...</form><!--the search--></header>
<main id="pagemain>...</main><!--the main content area-->
<footer id="pagemain>...</footer><!--the footer-->
</div>
CSS
#pagecontainer {
display:flex;
flex-direction:column;
min-height:100VH;
}
#pageheader {
position:sticky;
top:0PX;
...
}
#pagemain {
flex:1;
...
}
#pagefooter {
...
}
#pageheader form {
position:absolute;
right:0;
bottom:0;
...
}
我遇到的问题是,在 Firefox 中,搜索字段的位置正确——在标题的右下角——但在 Chrome(和其他 Webkit 浏览器中)它位于右下角页。 根据 MDN 关于位置的文章 (https://developer.mozilla.org/en-US/docs/Web/CSS/position),绝对定位的元素是 “相对于最近的定位祖先定位。如果定位的祖先不存在,则使用初始容器。” 很明显,Firefox 将 flex-positioned 元素视为已定位,但 Webkit 将它们视为正常流程。哪种行为是“正确的”?是否有一些我可以使用的后备?
谢谢, 汤姆
【问题讨论】: