html+css复习(六)

1.static定位

HTML:
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
<title>position属性</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="father">
  <div id="first">第一个盒子</div>
  <div id="second">第二个盒子</div>
  <div id="third">第三个盒子</div>
</div>
</body>
</html>
CSS:
div {
	margin:10px;
	padding:5px;
	font-size:12px;
	line-height:25px;
}
#father {
	border:1px #666 solid;
	padding:0;
}
#first {
	background-color:#f2bb6f;
	border:1px #B55A00 dashed;
}
#second {
	background-color:#003580;
	border:1px #0000A8 dashed;
}
#third {
	background-color:#f3f3f3;
	border:1px #395E4F dashed;
}

2.relative定位

HTML:
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
<title>position属性</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="father">
  <div id="first">第一个盒子</div>
  <div id="second">第二个盒子</div>
  <div id="third">第三个盒子</div>
</div>
</body>
</html>
CSS:
body{
	padding: 20px;
}
div {
	margin:10px;
	padding:5px;
	font-size:12px;
	line-height:25px;
}
#father {
	border:1px #666 solid;
	padding:0px;
}
#first {
	background-color:#f2bb6f;
	border:1px #B55A00 dashed;
	position:relative;
	top:-20px;
	left:20px;
}
#second {
	background-color:#003580;
	border:1px #0000A8 dashed;
}
#third {
	background-color:#f3f3f3;
	border:1px #395E4F dashed;
	position:relative;
	right:20px;
	bottom:30px;
}

3.浮动元素使用relative定位

HTML:
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
<title>position属性</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="father">
  <div id="first">第一个盒子</div>
  <div id="second">第二个盒子</div>
  <div id="third">第三个盒子</div>
</div>
</body>
</html>
CSS:
body{
	padding: 10px;
}
div {
	margin:10px;
	padding:5px;
	font-size:12px;
	line-height:25px;
}
#father {
	border:1px #666 solid;
	padding:0px;
}
#first {
	background-color:#f2bb6f;
	border:1px #B55A00 dashed;
	position:relative;
	right:20px;
	bottom:20px;
}
#second {
	background-color:#003580;
	border:1px #0000A8 dashed;
	float:right;
	position:relative;
	left:20px;
	top:-20px;
}
#third {
	background-color:#f3f3f3;
	border:1px #395E4F dashed;
}

4.absolute定位

HTML:
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
<title>position属性</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="father">
  <div id="first">第一个盒子</div>
  <div id="second">第二个盒子</div>
  <div id="third">第三个盒子</div>
</div>
</body>
</html>
CSS:
body{margin:0;}
div {
	padding:5px;
	font-size:12px;
	line-height:25px;
}
#father {
	border:1px #666 solid;
	margin:10px;
	position:relative;
}
#first {
	background-color:#f2bb6f;
	border:1px #B55A00 dashed;
}
#second {
	background-color:#003580;
	border:1px #0000A8 dashed;
	position:absolute;
	/* top: 0; */
	right: 30px;
	/*top: 30px;*/
	/* right:30px; */
}
#third {
	background-color:#f3f3f3;
	border:1px #395E4F dashed;
}

5.fixed定位

<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>fixed的使用</title>
    <style>
        body{
        height: 1000px;
        }
        div:nth-of-type(1) {  /*第一个div设置绝对定位*/
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            right: 0;
            bottom: 0;
        }
        div:nth-of-type(2) {  /*第二个div设置固定定位*/
            width: 50px;
            height: 50px;
            background: yellow;
            position: fixed;
            right: 0;
            bottom: 0;
        }
    </style>
</head>
<body>
<div>div1</div>
<div>div2</div>
</body>
</html>

6z-index属性

HTML:
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
<title>z-index属性</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="content">
  <ul>
    <li><img src="image/maple.jpg"  alt="香山红叶" /></li>
    <li class="tipText">京秋魅力&#8226;相约共赏香山红叶</li>
    <li class="tipBg"></li>
    <li>时间:11月16日 星期六 8:30</li>
    <li>地点:朝阳区西大望路珠江帝景K区正门前集合</li>
  </ul>
</div>
</body>
</html>
CSS:
ul, li {
	padding:0px;
	margin:0px;
	list-style-type:none;
}
#content {
	width:331px;
	overflow:hidden;
	padding:5px;
	font-size:12px;
	line-height:25px;
	border:1px #999 solid;
}
#content ul {
	position:relative;
}
.tipBg, .tipText {
	position:absolute;
	width:331px;
	height:25px;
	top:100px;
}
.tipText {
	color:#FFF;
	text-align:center;
	/*z-index:1;*/
}
.tipBg {
	background:#000;
	opacity:0.5;
	filter:alpha(opacity=50);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值