我正在开发一个基于WordPress的主题,其中包含isotope网格,当鼠标悬停在文章上时,应该在浏览器底部以固定位置显示文章标题。我有这个简化的结构:
<div id="main">
<article class="hubbub">
//article content
<h2 class="subtitled">
//h2 content
</h2>
</article>
</div>
通过 jQuery,在 <article>
元素上的悬停应该显示它的子元素 h2.subtitled
。<article>
元素是相对定位的,但通过 isotope 脚本获取绝对定位。而 h2.subtitled
则使用固定定位:.subtitled {
display: none;
position: fixed;
z-index: 999999999;
bottom: 20px;
left: 0;
width: 100%;
font-family: Arial, Helvetica, sans-serif;
font-size: 42px;
text-align: center;
color: yellow;
}
由于某种原因,h2.subtitle
元素相对于父级<article>
元素被固定定位在每个<article>
的底部。如果我将<h2>
放在<article>
之外,则相对于浏览器位置固定,但它们需要位于<article>
元素内,因为无限滚动会追加新的<article>
元素,它们也应包含<h2>
标题。
有人知道如何使其固定并相对于浏览器窗口吗?
谢谢!
fixed
定位会将元素固定在视口中,因此您可能有其他脚本或CSS覆盖了固定位置。 - DaniP