Homework8
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</body>
</html>
要求
- body的高度设为2000px,外边距设为0。
- 所有div标签的样式设置为:
- 宽度与高度均为200px;
- 背景颜色设置为lightblue;
- 外边距设置为20px;
- 第一个div的position属性为static。
- 第二个div的样式设置为:
- position的值为relative;
- left的值为50px;
- top的值为15px;
- 第三个div的样式设置为:
- position的值为absolute;
- 背景颜色为rgba(0, 0, 255, 0.5);
- left的值为30px;
- top的值为30px;
- 第四个div的样式设置为:
- position的值为fixed;
- 背景颜色为rgba(0, 255, 0, 0.5);
- left的值为100px;
- top的值为250px;
- 第十个div的样式为:
- position的值为sticky;
- 背景颜色为rgba(255, 0, 0, 0.5);
- bottom的值为10px;
css实现:
style>
body {
height: 2000px;
margin: 0;
}
div {
width: 200px;
height: 200px;
background-color: lightblue;
margin: 20px;
}
div:nth-of-type(2) {
position: relative;
left: 50px;
top: 15px;
}
div:nth-of-type(3) {
position: absolute;
left: 30px;
top: 30px;
background-color: rgba(0, 0, 255, 0.5);
}
div:nth-of-type(4) {
position: fixed;
left: 100px;
top: 250px;
background-color: rgba(0, 255, 0, 0.5);
}
div:nth-of-type(10) {
position: sticky;
bottom: 10px;
background-color: rgba(255, 0, 0, 0.5);
}
</style>
html+css:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
height: 2000px;
margin: 0;
}
div {
width: 200px;
height: 200px;
background-color: lightblue;
margin: 20px;
}
div:nth-of-type(2) {
position: relative;
left: 50px;
top: 15px;
}
div:nth-of-type(3) {
position: absolute;
left: 30px;
top: 30px;
background-color: rgba(0, 0, 255, 0.5);
}
div:nth-of-type(4) {
position: fixed;
left: 100px;
top: 250px;
background-color: rgba(0, 255, 0, 0.5);
}
div:nth-of-type(10) {
position: sticky;
bottom: 10px;
background-color: rgba(255, 0, 0, 0.5);
}
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</body>
</html>
实现界面:
加油