五、解决ie6下固定定位失效问题
1.fixed
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: fixed;
left: 50px;
top: 50px;
width: 100px;
height: 100px;
background: pink;
}
</style>
</head>
<body style="height: 3000px;">
<div id="test">
</div>
</body>
</html>
2.滚动条
① html 身上永远都不会有滚动条
② 如果 html 和 body 当中只有一个有 overflow属性,那么滚动条出现在html的上一层,也就是窗口
③ 如果要让 body 身上出现滚动条,那么 html 和 body 都要有 overflow属性
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html{
margin: 30px;
height: 80%;
border: 1px solid;
overflow: hidden;
}
body{
margin: 30px;
height: 80%;
border: 1px solid deeppink;
overflow: auto;
}
</style>
</head>
<body>
<div id="test" style="height: 3000px;">
</div>
</body>
</html>
3.禁止系统滚动条
禁止系统滚动条的做法:
① 将 html、body 都设置为 overflow:hidden
② 再声明一个元素 wrap ,充当视口
③将 wrap 元素设置为 overflow:auto,使滚动条出现在其身上
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html{
height: 100%;
overflow: hidden;
}
body{
height: 100%;
overflow: hidden;
}
#wrap{
height: 100%;
border: 1px solid deeppink;
overflow: auto;
}
</style>
</head>
<body>
<div id="wrap">
<div id="test" style="height: 3000px;">
</div>
</div>
</body>
</html>
4.利用绝对定位模拟固定定位
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html{
height: 100%;
overflow: hidden;
}
body{
height: 100%;
overflow: hidden;
}
#wrap{
height: 100%;
border: 1px solid deeppink;
overflow: auto;
}
#pink{
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 200px;
background: pink;
}
</style>
</head>
<body>
<!-- 初始包含块: 是一个视窗大小的矩形 -->
<div id="wrap">
<div id="pink">
</div>
<div id="test" style="height: 3000px;">
</div>
</div>
</body>
</html>
5.绝对定位
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
width: 200px;
height: 200px;
background: pink;
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body style="height: 3000px;">
<div id="test">
</div>
</body>
</html>
四、新增UI方案
3.新增UI样式
(4)边框图片
① border-image-source
② border-image-slice
③ border-image-repeat
④ border-image-width
⑤ border-image-outset
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 200px;
height: 200px;
border: 50px solid;
border-image-source: url(img/border-image.png);
border-image-slice: 33.333333%;
border-image-repeat: round;
border-image-width: 30px;
border-image-outset:10px;
}
</style>
</head>
<body>
<div id="test">
</div>
</body>
</html>
效果
(5)css2背景
① background-color
② background-image
③ background-repeat
④ background-position
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 200px;
height: 200px;
background-color:pink;
/* background-image: url(img/border-image.png),url(img/avatar.jpg); */
background-image: url(img/avatar.jpg);
background-repeat: no-repeat;
background-position: 10% 10%;
background-position: -40px -40px;
}
</style>
</head>
<body>
<div id="test">
</div>
</body>
</html>
⑤ background-attachment
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 200px;
height: 200px;
background-image: url(img/avatar.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
overflow: auto;
}
</style>
</head>
<body>
<div id="test">
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>哈哈<br>
</div>
</body>
</html>
(6)css3背景
① background-origin
② background-clip
示例: 默认情况下背景图片是从 padding box 开始绘制,从 border box 开始剪裁
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 300px;
height: 300px;
border: 50px solid rgba(0,0,0,.2);
padding: 50px;
background-color:pink;
background-image: url(img/avatar.jpg);
background-repeat: repeat;
background-origin: padding-box;
-webkit-background-clip: text;
font: bold 80px/300px "微软雅黑";
text-align: center;
color: rgba(0,0,0,.3);
}
</style>
</head>
<body>
<div id="test">
哈哈
</div>
</body>
</html>
效果
③ background-size
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#test{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 300px;
height: 300px;
border: 50px solid rgba(0,0,0,.2);
padding: 50px;
background-color:pink;
background-image: url(img/avatar.jpg);
background-repeat: no-repeat;
background-origin: padding-box;
background-clip: border-box;
background-size: 100%;
}
</style>
</head>
<body>
<div id="test">
</div>
</body>
</html>
效果
④ background