好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

css怎么把导航栏固定住

在css中,可以 利用 pos IT ion属性把导航栏固定住,只需要给导航栏元素添加“position:fixed;”样式,将导航栏相对于浏览器窗口进行固定定位即可,这样被固定的导航栏元素就不会随着滚动条的拖动而 改变 位置。

本教程操作环境:windows7系统、CSS3 && HT ML 5版、Dell G3 电 脑。

css怎么把导航栏固定住

可以给导航栏添加固定定位是导航来固定住。语法为“position:fixed;”。

示例如下:

<!DOCTY PE  html>
<html lang="en">
<head>
  < ;m eta charset="UTF-8">
  <meta n am e="viewport" content="width=device-width, initial -s cale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie= Edge ">
  <title>Document</title>
  <style type="text/css">
    *{m arg in:0;padding: 0;}
   ul{
       list-style -t ype: none;
       overflow: hidden;
       background -i mage:url(1118.02.png);
       position: fixed;
       top: 0;
       width: 100%;
       
   }  
   li {
       float: left;
   }   
   li a {
       dis play : block;
       color: white;
       text-align:  center ;
       padding: 14px 16px;
       text-decoration: none;
   }   
   li a:hover{
       background-color:  red ;
   }   
</style>
</head>
<body>
<ul>
   <li><a  hr ef=" # home">首页</a></li>
   <li><a href="#news">新闻动态</a></li>
   <li><a href="#contact">联系我们</a></li>
   <li><a href="#about">关于我们</a></li>
</ul>   
<div style="background-color:pink;h ei ght:1500px;"></div>
</body>
</html>

输出结果:

(学习视频分享:css视频教程)

以上就是css怎么把导航栏固定住的详细内容,更多请关注其它相关 文章 !

总结

以上是 为你收集整理的 css怎么把导航栏固定住 全部内容,希望文章能够帮你解决 css怎么把导航栏固定住 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于css怎么把导航栏固定住的详细内容...

  阅读:18次