04.粘滞定位.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=s, initial-scale=1.0">
    <title>导航条</title>
    <link rel="stylesheet" href="./css/reset.css">
    <!-- <style>
        .nav li{
            width: 166px;
            height: 48px;
            float: left;
            line-height: 48px;
            text-align: center;
        }
        .nav li:hover{
            background-color: rgba(0, 0, 0, .3);
        }
        .nav a{
            font-weight: bold;
            text-decoration: none;
            color: #333;
        }
        
    </style> -->
    <style>
        body{
            height: 3000px;
        }
        .nav{
            width: 1205px;
            height: 48px;
            background-color: #E8E7E3;
            margin: 100px auto;

            /* 
                粘滞定位(兼容性不是很好)
                    - 当元素的position属性设置为sticky时,则开启了元素的粘滞定位
                    - 粘滞定位和相对定位的特点基本一致,不同的是粘滞定位可以在元素到达某一位置时将其固定
            */
            position: sticky;
            top: 20px;
            left: 20px;
        }
        .nav li{
            /* 设置li向左浮动,以使菜单栏横向排列 */
            float: left;
            /* 设置li的高度 */
            height: 48px;
            /* 将文字在父元素中垂直居中 */
            line-height: 48px;
        }
        /* 设置a的样式 */
        .nav a{
            /* 将a转换为块元素 */
            display: block;
            text-decoration: none;
            color: #777777;
            font-size: 18px;
            padding: 0px 39px;
        }
        /* 设置鼠标移入的效果 */
        .nav a:hover{
            background-color: #3f3f3f;
            color: #E8E7E3;
        }
    </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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值