0319课堂笔记

导航栏

代码实现

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        a{color: #FFFF99;text-decoration: none;}
        a:hover{color:red;text-decoration: underline}
        .top-nav{padding: 10px 10px 0;font-size: 12px;wight:bold;
            margin: 1px 0 0 0;list-style: none;border-bottom:8px solid#DC4E1B;overflow: hidden ;background-color:#33b5e5 ;}
        .top-nav li{float: left;margin-right: 1px;
            color:#666666;display: block;width: 80px;text-align: center}
        .top-nav li a span{position: absolute;visibility: hidden}
        .top-nav li a:hover span{line-height: 20px;text-decoration: none;background: #DDDDDD;color: #666666;display: block;width: 80px;text-align: center}
    </style>
</head>
<body>

<li><a href="#">课程中心</a><span></span> </li>
<li><a href="#">学习中心</a><span></span> </li>
<li><a href="#">关于我们</a><span></span> </li>
</body>
</html>

方法2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        a:hover{color:red;text-decoration: underline}
        #top{padding: 10px 10px 0;font-size: 12px;font-wight:bold;
        margin: 1px 0 0 0;list-style: none;border-bottom:8px solid#DC4E1B;overflow: hidden ;background-color:#33b5e5 ;}
        #top nav{float: left;margin-right: 1px;
            line-height: 20px;text-decoration: none;background: #DDDDDD;color: #666666;display: block;
            width: 80px;text-align: center}
    </style>
</head>
<body>
<div class="top">
<div class="top nav" ><a href="#">课程中心</a></div>
    <div class="top nav" ><a href="#">学习中心</a></div>
        <div class="top nav" ><a href="#">关于我们</a></div>
</div>
</body>
</html>

 

知识点总结:

css的定位属性:

定位和没有定位:

css的position属性值有static(默认值),relative,absolute,fixed。分为两大类:positioned(relative,absolute,fixed)和unpositioned(static)。

1.static:默认值。表示该元素没有定位。

2.relative:相对定位。如果将元素设置为相对定位,可以作为绝对定位元素的参照物,对象不可层叠。

3.Fixed:固定定位。固定在视窗(即浏览器显示的整个页面)的某个位置,可以通过设置top,bottom,left,right属性设置相对于视窗的位置。

4.absolute:绝对定位。相对于最近的positioned祖先元素偏移(当该元素的父元素都不是positioned,则相对于body元素偏移)。通过设置top,bottom,left,right属性设置偏移。

绝对定位可以这样理解:

 
1.HTML页面是地面,绝对定位的元素则把它从文档流里脱离出来,并且默认盖在HTML页面上面
2.当有多个absolute元素重叠时,怎样决定他们的上下级关系,这就需要一个特殊的属性:z-index,可以把它理解成这个绝对定位元素在第几层。默认z-index=0,即该元素就盖在地面上,z-index=1则表示该元素在地面下面,z-index越高,则表示该元素在越高层。
relative 相对定位实例: 

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        html body
        {
            margin: 0px;
            padding: 0px;
        }
        #parent
        {
            width: 200px;
            height: 200px;
            border: solid 5px black;
            padding: 0px;
            position: relative;
            background-color: green;
            top: 15px;
            left: 15px;
        }
        #sub1
        {
            width: 100px;
            height: 100px;
            background-color: blue;
        }
        #sub2
        {
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="parent">
        <div id="sub1">
        </div>
        <div id="sub2">
        </div>
    </div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值