今天写了个简单的页面,再熟悉了一下div+css布局,写的还可以,以后还要多练习。此外还进一步学习了定位相关知识。
1、相对定位:
相对定位有坑,所以一般不用于做“压盖”效果。页面中,效果极小。就两个作用:
1) 微调元素
2) 做绝对定位的参考,子绝父相
2、绝对定位:
绝对定位的参考点,如果用top描述,那么定位参考点就是页面的左上角,而不是浏览器的左上角。
绝对定位的盒子,是脱离标准文档流的。所以,所有的标准文档流的性质,绝对定位之后都不遵守了。
绝对定位之后,标签就不区分所谓的行内元素、块级元素了,不需要display:block;就可以设置宽、高了
绝对定位之后,所有标准流的规则,都不适用了。所以margin:0 auto;失效。新的居中方法如下:
{
}width: 600px;
height: 60px;
position: absolute;
left: 50%;
top: 0;
margin-left: -300px;// → 宽度的一半
}
3、固定定位:
固定定位,就是相对浏览器窗口定位。页面如何滚动,这个盒子显示的位置不变。固定定位脱标!
4、z-index值表示谁压着谁。数值大的压盖住数值小的。
●只有定位了的元素,才能有z-index值。也就是说,不管相对定位、绝对定位、固定定位,都可以使用z-index值。而浮动的东西不能用。
● z-index值没有单位,就是一个正整数。默认的z-index值是0。
● 如果大家都没有z-index值,或者z-index值一样,那么谁写在HTML后面,谁在上面能压住别人。定位了的元素,永远能够压住没有定位的元素。
● 从父现象:父亲怂了,儿子再牛逼也没用。
没有单位:z-index: 988;
博雅实例代码如下:
1<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>博雅</title>
<link rel="stylesheet" type="text/css" href="css/index2.css">
</head>
<body>
<div class="header">
<div class="inner">
<div class="logo fl">
<a href=""><img src="images/logo.png" alt=""></a>
</div>
<div class="nav fl">
<ul>
<li class="current"><a href="">首页</a></li>
<li><a href="">博雅游戏</a></li>
<li><a href="">博雅新闻</a></li>
<li><a href="">关于我们</a></li>
<li><a href="">客服中心</a></li>
<li><a href="">投资者关系</a></li>
</ul>
</div>
<div class="join fl">
<a href="">加入我们</a>
</div>
</div>
</div>
<div class="banner"></div>
<div class="content inner ">
<ul>
<li>
<img src="images/pro1.jpg" alt="">
<h3>BRT宣传片</h3>
<a href="">点击播放</a>
</li>
<li>
<img src="images/pro2.jpg" alt="">
<h3>BRT宣传片</h3>
<a href="">点击播放</a>
</li>
<li>
<img src="images/pro3.jpg" alt="">
<h3>BRT宣传片</h3>
<a href="">点击播放</a>
</li>
<li class="last">
<img src="images/pro4.jpg" alt="">
<h3>BRT宣传片</h3>
<a href="">点击播放</a>
</li>
</ul>
</div>
<div class="info inner clearfix">
<div class="news fl">
<ul>
<li>
<span>9 / 18</span>
<a href="">2015博雅国际扑克大赛在澳门落幕</a>
</li>
<li>
<span>9 / 18</span>
<a href="">2015博雅国际扑克大赛在澳门落幕</a>
</li>
<li>
<span>9 / 18</span>
<a href="">2015博雅国际扑克大赛在澳门落幕</a>
</li>
<li>
<span>9 / 18</span>
<a href="">2015博雅国际扑克大赛在澳门落幕</a>
</li>
</ul>
</div>
<div class="jobs fl">
<div class="title">
<h2>专场招聘</h2>
<span>BOYAYA JOBS</span>
<a class="more fl" href="">more+</a>
</div>
<ul class="con">
<li><h4>专场招聘岗位:</h4></li>
<li><a href="">PHP开发工程师</a></li>
<li><a href="">PHP开发工程师</a></li>
<li><a href="">PHP开发工程师</a></li>
<li><a href="">PHP开发工程师</a></li>
</ul>
</div>
</div>
<div class="footer">
<div class="inner">
<div class="left fl">
<span><a href="">网站地图</a> | </span>
<span><a href="">免责声明</a></span>
</div>
<div class="right fl">
<span>
Copyright©2014-2020 博雅互动(BoyaaInteractive) 粤ICP备05062536号 增值电信业务许可证:粤B2-20110513
</span>
<img src="images/govIcon.gif" alt="">
</div>
</div>
</div>
</body>
</html>
css部分
@charset "UTF-8";
/*css 初始化 */
*{
margin:0;
padding:0;
}
a{
text-decoration: none;
}
fieldset, img,input,button {
border:none;
outline-style:none;
}
ul, ol {
list-style:none;
}
input {
font-family: "SimSun","宋体";
}
select, input {
vertical-align:middle;
}
select, input, textarea {
font-size:12px;
margin:0; }
textarea {
resize:none;
} /*防止拖动*/
img {
border:0;
vertical-align:middle;
} /* 去掉图片低测默认的3像素空白缝隙*/
table {
border-collapse:collapse;
}
body {
font-family: "微软雅黑";
/*font:12px/150% Arial,Verdana,"\5b8b\4f53";*/
color:#666;
background:#fff
}
.clearfix:before,.clearfix:after{
content:"";
display:table;
}
.clearfix:after{clear:both;}
.clearfix{
*zoom:1;/*IE/7/6*/
}
.fl{
float:left;
}
.fr{
float:right;
}
.header{
height:58px;
background: #191D3A;
text-align: center;
}
.inner{
width:1000px;
margin: 0 auto;
}
.header .inner .logo{
}
.header .nav{
}
.header .nav ul{
}
.header .nav ul li{
float: left;
width:100px;
height:58px;
line-height: 58px;
}
.header .nav ul li a{
display: block;
width:100px;
height:58px;
color: #7E7B86;
}
.header .nav ul li a:hover{
color: #fff;
background: #252947;
}
.header .nav .current a{
color: #fff;
background: #252947;
}
.header .join{
background: #38B774;
border: 1px solid #309767;
border-radius: 4px;
margin-left: 50px;
margin-top: 12px;
}
.header .join a{
color: #fff;
display: block;
width:100px;
height:34px;
line-height: 32px;
}
.banner{
height:463px;
background: url(../images/banner.jpg) no-repeat center top;
}
.content{
padding-top: 50px;
height:232px;
border-bottom: 1px solid #ccc;
}
.content ul li{
text-align: center;
width:218px;
height:229px;
margin-right: 43px;
float:left;
}
.news{
height:300px;
}
.content ul .last{
margin-right: 0;
width:217px;
}
.content ul img{
width:100%;
height:130px;
}
.content ul li h3{
font-size: 16px;
line-height: 28px;
}
.content ul li a{
color: #62C093;
font-size: 16px;
line-height: 28px;
padding-right: 10px;
background: url(../images/sanjiaoxing.png) no-repeat right 8px;
}
.info{
padding-top: 50px;
}
.info .news{
width:500px;
height:190px;
background: url(../images/bynewsbg.jpg) no-repeat;
padding-top: 120px;
}
.info .news li{
margin: 0 18px;
line-height: 44px;
border-bottom: 1px solid #ccc;
}
.info .news li span{
color: #C8C5D1;
margin-right: 20px;
}
.info .news li a{
font-size: 14px;
color: #494D6B;
}
.info .news li a:hover{
color: #bbb;
}
.info .jobs{
width:500px;
height:310px;
background: url(../images/byhrbg3.jpg) no-repeat;
position: relative;
}
.info .jobs h2{
color: #fff;
padding: 42px 0 0 82px;
}
.info .jobs span{
color: #fff;
font-size: 12px;
padding-left: 82px;
}
.info .jobs .more{
display: block;
color: #fff;
width:63px;
height:26px;
text-align: center;
line-height: 26px;
border: 1px solid #fff;
border-radius: 4px;
position: absolute;
top: 40px;
left:220px;
}
.info .jobs .con{
position: absolute;
top: 115;
left: 24px;
}
.info .jobs .con li h4{
color: #fff;
font-size: 14px;
top: 114px;
left: 24px;
}
.info .jobs .con li{
line-height: 36px;
}
.info .jobs .con li a{
display: block;
width:304px;
font-size: 14px;
color: #fff;
border-bottom: 1px solid #ccc;
}
.info .jobs .con li a:hover{
color:#191D3A;
}
.footer{
height:90px;
margin-top: 56px;
background: #191D3A;
position: relative;
}
.footer .left{
}
.footer .left a{
color: #46475B;
font-size: 12px;
line-height: 90px;
}
.footer .left a:hover{
color: #fff;
}
.footer .right span{
font-size: 12px;
line-height: 90px;
padding-left: 170px;
}
.footer .right img{
width:40px;
height:50px;
}
运行效果:

网友评论