定位元素

 

相对定位

 

 

绝对定位

固定定位

粘滞定位

导航条-粘滞定位


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导航条</title>
    <link rel="stylesheet" href="../效果/reset.css">
    <style>
        body{
            height: 3000px;
        }
        .nav{
            width: 1206px;
            height: 48px;
            background-color:#e6e7e2 ;
            margin: 100px auto;

            position: sticky;
            top: 10px;

        }


        .nav li{
            float: left;
            /* 高度居中 */
            /* height: 48px; */
            line-height: 48px;
            
        }

       .nav a{
           /* 转换成块元素 */
            display: block;
            /* 字体颜色 */
            color: #9b9c97;
            /* 去掉下划线 */
            text-decoration: none;
            /* 字体大小 */
            font-size: 20px;
            /* 使居中 */
            padding: 0px 40px;
        }

        .nav a:hover{
            background-color: #a2a39d;
            color: aliceblue;
        }


    </style>
</head>
<body>
    
    <ul class="nav">
        <li>
            <a href="">HTML/CSS</a>
        </li>
        <li>
            <a href="">Browser Side</a>
        </li>
        <li>
            <a href="">Server Side</a>
        </li>
        <li>
            <a href="">Programming</a>
        </li>
        <li>
            <a href="">XML</a>
        </li>
        <li>
            <a href="">Web Building</a>
        </li>
        <li>
            <a href="">Reference</a>
        </li>
    </ul>
</body>
</html>

多数不用这种方法,因为兼容性问题,特别是ie

 

开启定位之后

 

------------恢复内容结束------------

posted @ 2022-04-24 23:27  Eveeee  阅读(38)  评论(0)    收藏  举报