<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景</title>
<style>
div{
width: 1000px;
height: 1000px;
/*默认铺满整个屏幕*/
background-image: url(../images/girl.png);
/* 不平铺*/
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
背景图片位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 1000px;
height: 1000px;
/*默认铺满整个屏幕*/
background-image: url(../images/logo.png);
background-color: yellowgreen;
/* 不平铺*/
background-repeat: no-repeat;
/*精确单位*/
/*background-position: 20px 50px;*/
/*background-position: center top;*/
/*background-position: left top;*/
/*background-position: bottom;*/
}
</style>
</head>
<body>
<div></div>
</body>
</html>
固定背景
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 1000px;
height: 1000px;
/*默认铺满整个屏幕*/
background-image: url(../images/girl.png);
/* 不平铺*/
background-repeat: no-repeat;
/* 背景固定 scroll*/
background-attachment: fixed;
}
</style>
</head>
<body>
<div>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
</div>
</body>
</html>
背景复合写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
/*背景固定,背景不平铺,背景图片*/
width: 1000px;
height: 1000px;
/*默认铺满整个屏幕*/
/*background-image: url(../images/girl.png);*/
/* 不平铺*/
/* background-repeat: no-repeat;*/
/* 背景固定 scroll*/
/* background-attachment: fixed;*/
/* background: url(../images/girl.png) no-repeat fixed;*/
background: no-repeat fixed url(../images/girl.png) ;
}
</style>
</head>
<body>
<div>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
<p>墨染千秋,海纳百川,我叫墨川</p>
</div>
</body>
</html>
05_border.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 300px;
height: 300px;
background-color: red;
/*复合样式*/
/*border: 1px solid chartreuse;*/
border-width: 5px 7px 10px 15px;
border-style: solid;
border-color: blue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
06_padding.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 300px;
height: 300px;
background-color: red;
/*内边距会撑开盒子*/
/*padding: 10px;*/
padding-bottom: 10px;
border-bottom: 10px solid skyblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
07_margin.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 200px;
height: 200px;
/*四个方向的值一样 上右下左 顺时针*/
/*margin: 100px;*/
/* 上下 左右*/
/*margin: 100px auto;*/
/* 上 左右 下*/
margin: 100px 200px 400px;
background-color: brown;
/*display: inline-block;*/
/*margin-left: 40px;*/
}
.box{
width: 300px;
height: 300px;
background-color: blue;
}
</style>
</head>
<body>
<div></div>
<div class="box"></div>
</body>
</html>
08_外边距塌陷.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box{
width: 300px;
height: 300px;
background-color: skyblue;
/* 解决外边距塌陷问题*/
overflow: hidden;
}
.box div{
width: 500px;
height: 200px;
background-color: coral;
margin: 50px;
}
</style>
</head>
<body>
<div class="box">
<div></div>
</div>
</body>
</html>
09_小结.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding:0;
}
div{
width: 100px;
height: 100px;
border: 10px solid red;
background-color: #58b2ff;
}
</style>
</head>
<body>
<div>
盒子宽=样式宽+内边距+外边距+边框
</div>
</body>
</html>
10_浮动.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.wrap{
width: 200px;
height: 200px;
background-color: red;
float: right;
}
.box{
width: 200px;
height: 200px;
background-color: skyblue;
float: left;
}
</style>
</head>
<body>
<div class="wrap"></div>
<div class="box"></div>
</body>
</html>
11_高度塌陷.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="reset.css">
<style>
ul{
border: 1px solid red;
/*position: absolute;*/
}
li{
list-style: none;
width: 50px;
height: 50px;
background-color: slateblue;
float: left;
/* 文字居中*/
text-align: center;
line-height: 50px;
margin: 2px 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<ul class="clearfix">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</body>
</html>
12_定位.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.wrap{
width: 200px;
height: 200px;
background-color: slateblue;
/* 相对定位*/
/* position: relative;*/
/*绝对定位 脱离文档流,原先的位置会填充*/
position: absolute;
top: 120px;
left: 200px;
}
.box{
width: 200px;
height: 200px;
background-color: gold;
}
</style>
</head>
<body>
<div class="wrap"></div>
<div class="box"></div>
</body>
</html>
13_固定定位.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
height: 2500px;
}
div{
width: 300px;
height: 300px;
}
.box{
background-color: gold;
position: fixed;
right: 50%;
}
</style>
</head>
<body>
<div class="wrap"></div>
<div class="box"></div>
</body>
</html>
14_定位补充.html - 代码阅读
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
li{
list-style: none;
width: 50px;
height: 50px;
position: absolute;
}
.box1{
background-color: red;
z-index: 2;
}
.box2{
background-color: skyblue;
z-index: 1;
}
.box3{
background-color: darkgreen;
z-index: 1;
}
.box4{
background-color: pink;
z-index: 1;
}
</style>
</head>
<body>
<!--多行同时编辑 按住alt键 鼠标点击-->
<ul>
<li class="box1"></li>
<li class="box2"></li>
<li class="box3"></li>
<li class="box4"></li>
</ul>
</body>
</html>