“位置:粘性;” 无法正常工作的CSS和HTML

“位置:粘性;” 无法正常工作的CSS和HTML,第1张

位置:粘性;” 无法正常工作的CSS和HTML

粘性定位是相对定位和固定定位的混合。将该元素视为相对位置,直到它超过指定的阈值为止,此时将其视为固定位置。

您必须指定的至少一个阈值

top
right
bottom
,或
left
为粘稠定位像预期的那样。否则,将无法与相对位置区分开。[资料来源:MDN ]

因此,在您的示例中,您必须使用

top
属性来定义最终应粘贴的位置。

html, body {  height: 200%;}nav {  position: sticky;  position: -webkit-sticky;  top: 0; }.nav-selections {  text-transform: uppercase;  letter-spacing: 5px;  font: 18px "lato", sans-serif;  display: inline-block;  text-decoration: none;  color: white;  padding: 18px;  float: right;  margin-left: 50px;  transition: 1.5s;}.nav-selections:hover {  transition: 1.5s;  color: black;}ul {  background-color: #B79b58;  overflow: auto;}li {  list-style-type: none;}<nav>  <ul align="left">    <li><a href="#/contact"  >Contact</a></li>    <li><a href="#/about" >about</a></li>    <li><a href="#/products" >Products</a></li>    <li><a href="#" >Home</a></li>  </ul></nav>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5566685.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存