position定位,常用的有fixed,relative和absolute,其中:
fixed:固定定位,相对于body定位;
relative:相对定位,相对于其正常位置进行定位;
absolute:绝对定位,相对于父级定位;
其中要注意:子绝父相;在进行绝对定位的时候,一定在在期父级元素给一个相对定位;
实例
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>优酷-这世界很酷</title> <link rel="icon" type="image/x-icon" href="static/images/1.ico"> <link rel="stylesheet" type="text/css" href="static/font-awesome/css/font-awesome.min.css"> <style type="text/css"> *{margin: 0;padding-left: 0;} li{list-style: none;float: left;} a{text-decoration: none;color: #000;} small{color: #989898;} .mr{margin-right: 10px;} .mt{margin-top: 20px;} .l{float: left;} .r{float: right;} .clear{clear: both;} .contents{ width: 1740px; margin: 0 auto; } .content{ width: 100%; margin-top: 20px; } .contentUL{line-height: 70px;} .hot_tv img{ /*margin:5px;*/ width: 240px; height: 360px; } .tab li{margin-left: 25px;} .big_show{ width: 490px; height: 350px; margin:0 10px 0 0; } .tv_tab{ width: 1240px; } .tv_tab img{ margin:0px 4px ; width: 240px; height: 135px; } .tv_tab li{ margin-bottom: 16px; } /*轮播模块+头部导航*/ .header{ position: relative;/*相对定位*/ width: 100%; height:520px; background:rgb(50,0,1); } /*轮播图*/ .pic_show{ width: 1664px; height:520px; background: url(static/images/header1.jpg); margin: 0 auto; position: relative; } .bg{ /*opacity:1;*/ width:100%; height: 100%; background: url(static/images/header_1.png); position: absolute;left: 0;top:0;z-index:999;/*绝对定位*/ } /*轮播上的logo+搜索框*/ .header_ul{ position: fixed;top:0;left:90px;z-index: 1000; } .logo form{ width: 500px; height: 40px; position: relative;margin-left:500px;/*top: -30px;*/ display: inline-block; } .logo input{ width: 480px; height: 40px; border-radius: 100px; border:none; background:rgba(255,255,255,0.5); outline: none; padding-left: 20px; color: #fff; } .logo button{ width: 90px; height: 42px; border-top-right-radius: 30px; border-bottom-right-radius: 30px; border: none; background:#B30702; color: #fff; position:absolute;right:0;top:0; } .menu_li a,i{color: rgba(234,234,234,0.5);} .menu_li li{ padding: 0 10px; text-align: center; font-size: 12px; position: relative; } .menu_li i{ font-size: 18px; /*font-weight: bold;*/ } .menu_li li:hover a{color:#48ADF2; } .menu_li li:hover i{color:#48ADF2; } .menu_li .box{ position: absolute;top: 50px;right: -5px; background:#fff; padding: 20px; display: none; } .menu_li p{color:#ccc;font-size: 16px;} .menu_li button{ background: #2798ff; color: #fff; border:none; width:240px; height: 36px; border-radius: 30px; margin-top: 15px; } .menu_li li:hover .box{display: block;} .menu_li .log a,i{ color: #ccc; font-size: 12px; } .menu_li .log{ line-height: 20px; } .menu_li ul{ width: 280px; } .menu_li .box_icon{ width: 120px; height: 120px; } .menu_li .box_icon a,i{ color: #ccc; font-size: 14px; } </style> </head> <body> <!-- 头部轮播图+搜索 --> <div class="header"> <div class="pic_show"> <div class="bg"></div> <div class="contents header_ul"> <div class="logo l mt"> <a href=""><img src="static/images/logo.png""></a> <form> <input type="text" name=""> <button>全搜索</button> </form> </div> <ul class="menu_li r mt"> <li><i class="fa fa-viacoin" style="color: #c4a25a" ></i><br><a href="" style="color: #c4a25a">VIP</a></li> <li><i class="fa fa-feed"></i><br><a>订阅</a></li> <li><i class="fa fa-clock-o"></i><br><a>记录</a> <div class="box"> <ul class="log"> <li>今天</li> <li> <ul> <li><a href=""></a>......</li> <li><i class="fa fa-television">已收看**%</i></li> <li><a href=""></a>......</li> <li><i class="fa fa-television">已收看**%</i></li> </ul> <li>一周内</li> <li> <ul > <li><a href=""></a>......</li> <li><i class="fa fa-television">已收看**%</i></li> <li><a href=""></a>......</li> <li><i class="fa fa-television">已收看**%</i></li> </ul> </li> </ul> </div> </li> <li><i class="fa fa-arrow-up"></i><br><a>上传</a> <div class="box"> <span class="arrow"></span> <p>登录使用更多功能</p> <button>登录/注册</button> </div> </li> <li><i class="fa fa-television"></i><br><a>客户端</a> <div class="box" > <ul > <li class="box_icon" > <a href="#"> <img src="static/images/icon.png"><br> <span>优酷客户端</span> </a><br> <small>快速.稳定的观看体验</small> </li> <li class="box_icon"> <a href="#"> <img src="static/images/qr.jpg" style="width: 70px;height: 70px;margin-top: 3px;"><br> <span>优酷移动APP</span> </a><br> <small>全网独播尽在手中</small> </li> </ul> <p><a href=""><i class="fa fa-television">优酷TV版</i></a>CIBN酷喵影视智能电视App</p> </div> </li> <li><a href=""><img src="static/images/80.png" width="40px" style="margin-top: -5px;"></a> <div class="box"> <span class="arrow"></span> <p>登录使用更多功能</p> <button>登录/注册</button> </div> </li> </ul> </div> <div class="clear"></div> </div> </div> <!-- 分类标签 --> <div class="contents"> <div class="content"> <div class="contentUL"> <h2>正在热播</h2> </div> <ul class="hot_tv"> <li class="mr"> <a href="#"> <img src="static/images/a.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr"> <a href="#"> <img src="static/images/b.jpg"><br> <span>摘金奇缘</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr"> <a href="#"> <img src="static/images/c.jpg"><br> <span>王牌对王牌</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr"> <a href="#"> <img src="static/images/d.jpg"><br> <span>我们村里人</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr"> <a href="#"> <img src="static/images/e.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr"> <a href="#"> <img src="static/images/f.jpg"><br> <span>大城小聚</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li class="mr> <a href="#"> <img src="static/images/g.jpg"><br> <span>托你缇娜</span> </a><br> <small>低调的宁夏 美了四季</small> </li> </ul> </div> <div class="clear"></div> <div class="content"> <div class="contentUL"> <h2 class="l mr">剧集 > </h2> <ul class="tab 1"> <li>最新</li> <li>大陆剧</li> <li>日韩剧</li> <li>港台剧</li> <li>英美剧</li> </ul> </div> <div class="clear"></div> <div class="tv_show"> <div class="big_show l mr"> <a href="#"> <img src="static/images/tv.jpg"><br> <span>逆流而上的你..爆笑</span> </a><br> <small>新晋辣妈萌爸!庞月明玛丽咸鱼夫妻带娃逆袭!</small> </div> <ul class="tv_tab l"> <li > <a href="#"> <img src="static/images/tv1.jpg"><br> <span>都挺好</span> </a><br> <small>姚晨郭京飞陷亲情漩涡</small> </li> <li> <a href="#"> <img src="static/images/tv2.jpg"><br> <span>乡村爱情11</span> </a><br> <small>刘能赵四争C位</small> </li> <li > <a href="#"> <img src="static/images/tv3.jpg"><br> <span>小女花不弃</span> </a><br> <small>林依晨张彬彬苏甜来袭</small> </li> <li > <a href="#"> <img src="static/images/tv4.jpg"><br> <span>春暖花又开</span> </a><br> <small>姚芊羽李建上演新农村创业</small> </li> <li> <a href="#"> <img src="static/images/tv5.jpg"><br> <span>老中医</span> </a><br> <small>陈宝国冯远征许晴弘扬医道</small> </li> <li> <a href="#"> <img src="static/images/tv1.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li > <a href="#"> <img src="static/images/tv2.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li> <a href="#"> <img src="static/images/tv3.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li> <a href="#"> <img src="static/images/tv4.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> <li> <a href="#"> <img src="static/images/tv5.jpg"><br> <span>瞰中国:宁夏</span> </a><br> <small>低调的宁夏 美了四季</small> </li> </ul> </div> </div> <div class="clear"></div> </div> </body>
运行实例 »点击 "运行实例" 按钮查看在线实例
- 2 本次笔记较少,就没有上传笔记! 心得体会:
a边框占像素,设置的时候要进行调整,不然达不到满意效果;
b有时候元素需要进行转化,才能对其进行约束,这个要自己把握,多联系;