我的 Markdown 看起来像 -
<body>
<header>
<div class"logo" />
<div class"contact-info" />
<div class="sticky-navigation"/>
</header>
<main>
<!-- content -->
</main>
</body>
我需要用 sticky-navigation
制作 div当用户滚动 body 时,它的行为就像一个粘性导航。有没有办法使用 position:sticky
做同样的事情?
据我所知,position:sticky
的使用高度依赖于标记,并且只适用于整个 <header/>
.
最佳答案
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%; /* Full width */
如果你只使用 css - 那么你可以使用 position:fixed
关于html - 我可以在父容器外使用 CSS `position:sticky` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44253377/