我可以在父容器外使用CSS`position:sticky`吗?

时间:2017-05-30 04:21:53

标签: html css css-position sticky

我的降价看起来像 -

<body>
  <header>
   <div class"logo" />
   <div class"contact-info" />
   <div class="sticky-navigation"/>
  </header>
<main>
  <!-- content -->
</main>
</body>

当用户滚动身体时,我需要使用类sticky-navigation的div表现得像粘性导航。有没有办法使用position:sticky来做同样的事情?

据我所知,position:sticky的使用高度依赖于标记,并且仅适用于整个<header/>

1 个答案:

答案 0 :(得分:-3)

&#13;
&#13;
position: fixed; /* Set the navbar to fixed position */
    top: 0; /* Position the navbar at the top of the page */
    width: 100%; /* Full width */
&#13;
&#13;
&#13;

如果你只使用css - 你可以使用position:fixed