我有以下HTML元素。两者都有粘性的CSS位置属性。但是,只有fieldset起作用,div才能正常运行。我的代码有问题吗?
HTML:
#sticky-test {
background: red;
position: -webkit-sticky;
position: sticky;
top: 140px;
z-index: 9;
}
#sticky-search-query {
position: -webkit-sticky;
position: sticky;
top: 125px;
}
<fieldset id="sticky-search-query" class="pure-u-1-1">
<label>Query</label> @Html.Kendo().TextBoxFor(m => m.SearchQuery).HtmlAttributes(new { style="width:100%;", autofocus="true", onkeypress="fmp.search.submitSearchByEnter(event)"})
</fieldset>
<div id="sticky-test" class="pure-u-1-1">
<p>Test</p>
</div>
这是屏幕截图,请注意字段集就位,但是包含段落的div确实应用了粘性定位: