笔记1
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body style="margin: 0;">
<div class="div-outer">
<div class="div-inner"></div>
<div class="div-inner-1"></div>
</div>
<br>
<div class="div-outer1">
<div class="div-inner2">
123
</div>
</div>
<br>
<div class="div-outer2">
<div class="div-inner3">
1
</div>
<div class="div-inner4">
2
</div>
<div class="div-inner5">
3
</div>
</div>
</body>
</html>
style.css
/*1*/
.div-outer {
width: 300px;
height: 400px;
background-color: lightblue;
/*不让子元素带父元素,让top边距不起作用*/
/* border-top: 1px solid; */
/* padding-top: 1px; */
/* overflow: hidden; */
}
/*不让子元素带父元素,让top边距不起作用*/
.div-outer::before {
content: "";
display: table;
}
.div-inner {
width: 100px;
height: 100px;
background-color: darkred;
/*上下是最大的生效*/
/*左右是相加*/
margin-bottom: 20px;
margin-left: 20px;
/*水平居中实现,上下实现不了*/
/* margin: 10px auto; */
}
.div-inner-1 {
width: 100px;
height: 100px;
background-color: darkgreen;
/*最大的生效*/
margin-top: 30px;
margin-left: 30px;
}
/*2*/
.div-outer1 {
width: 300px;
height: 400px;
background-color: lightblue;
padding: 20px 0 0 30px;
}
.div-inner2 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
/*content-box增加内边距和边框都会让div变大*/
box-sizing: border-box;
padding: 20px 0 0 10%;
border: 10px solid black;
}
/*3*/
.div-outer2 {
width: 300px;
height: 400px;
background-color: lightblue;
margin: 100px;
}
.div-inner3 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
display: inline-block;
position: relative;
z-index: 2;
}
.div-inner4 {
width: 100px;
height: 100px;
background-color: darkgreen;
color: white;
margin: 10px;
display: inline-block;
position: relative;
top: 30px;
left: -100px;
}
.div-inner5 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
display: inline-block;
}
笔记2(绝对定位、固定定位)
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body style="margin: 0;">
<div class="div-outer">
<div class="div-inner-1">
1
</div>
<div class="div-inner-2">
2
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-4">
回到顶部
</div>
</div>
</body>
</html>
style.css
.div-outer {
width: 300px;
height: 3000px;
background-color: lightblue;
margin: 100px;
}
.div-outer::before {
content: "";
display: table;
}
.div-inner-1 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
display: inline-block;
}
.div-inner-2 {
width: 100px;
height: 100px;
background-color: darkgreen;
color: white;
display: inline-block;
/*脱离文档流*/
position: absolute;
top: 100px;
left: 20px;
}
.div-inner-3 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
display: inline-block;
}
.div-inner-4 {
width: 30px;
height: 100px;
background-color: darkgreen;
color: white;
display: inline-block;
position: fixed;
top: 200px;
right: 0;
}
笔记3(粘性定位)
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body style="margin: 0;">
<div class="div-outer">
<div class="div-inner-2">
2
</div>
<div class="div-inner-1">
1
</div>
<div class="div-inner-2">
2
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-2">
2
</div>
</div>
</body>
</html>
style.css
.div-outer {
width: 300px;
height: 3000px;
background-color: lightblue;
margin: 100px;
}
.div-outer::before {
content: "";
display: table;
}
.div-inner-1 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
position: sticky;
top: 0;
}
.div-inner-2 {
width: 100px;
height: 1000px;
background-color: darkgreen;
color: white;
margin: 10px;
}
.div-inner-3 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
margin: 10px;
position: sticky;
bottom: 10px;
}
笔记4(浮动)
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body style="margin: 0;">
<div class="div-outer">
<div class="div-inner-2">
2
</div>
<div class="div-inner-1">
1
</div>
<div class="div-inner-2">
2
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-2">
2
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-3">
3
</div>
<div class="div-inner-4">
</div>
</div>
</body>
</html>
style.css
.div-outer {
width: 100%;
height: 3000px;
background-color: lightblue;
}
.div-outer::before {
content: "";
display: table;
}
.div-inner-1 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
position: sticky;
top: 0;
/*inline-block左右有缝隙,浮动无缝隙*/
float: left;
}
.div-inner-2 {
width: 100px;
height: 100px;
background-color: darkgreen;
color: white;
float: left;
}
.div-inner-3 {
width: 100px;
height: 100px;
background-color: darkred;
color: white;
position: sticky;
bottom: 10px;
float: left;
}
.div-inner-4 {
width: 300px;
height: 300px;
background-color: darkgoldenrod;
position: relative;
z-index: 3;
/*清除左浮动*/
clear: left;
}
stack overflow小名片
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body>
<div class="user-card">
<div class="user-card-head">
asked Feb 9, 2019 at 18:18
</div>
<div class="user-card-body">
<div class="user-card-body-photo">
<a href="https://www.acwing.com/user/myspace/index/458546/" target="_blank"><img
src="static/images/re.jpg"></a>
</div>
<div class="user-card-body-info">
<div class="user-card-body-info-username">
<a href="https://www.acwing.com/user/myspace/index/458546/" target="_blank">diaochangxiao</a>
</div>
<div class="user-card-body-info-reputation">
<span style="color:#6A737C; font-weight:bold">1,024</span>
<div class="user-card-body-info-reputation-item" style="background-color:#EECC01;"></div>
3
<div class="user-card-body-info-reputation-item" style="background-color:#B4B8BC;"></div>
14
<div class="user-card-body-info-reputation-item" style="background-color:#D1A684;"></div>
25
</div>
</div>
</div>
</div>
</body>
</html>
style.css
.user-card {
width: 200px;
height: 67.69px;
background-color: #D9EAF7;
margin: 100px auto;
padding: 5px 6px 7px 7px;
box-sizing: border-box;
}
.user-card-head {
font-size: 12px;
color: #6A737C;
margin: 1px 0 4px 0;
}
.user-card-body-photo img {
width: 32px;
height: 32px;
border-radius: 3px;
}
.user-card-body-photo {
float: left;
}
.user-card-body-info {
float: left;
margin-left: 8px;
}
.user-card-body-info-username {
height: 14px;
line-height: 14px;
margin-bottom: 4px;
}
.user-card-body-info-username>a {
font-size: 13px;
color: #0074CC;
text-decoration: none;
}
.user-card-body-info-reputation {
font-size: 12px;
color: #838C95;
height: 14px;
line-height: 14px;
}
.user-card-body-info-reputation-item {
width: 6px;
height: 6px;
display: inline-block;
border-radius: 50%;
margin: 0 3px 0 2px;
position: relative;
top: -2px;
}
b站小名片
index.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>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
</head>
<body>
<div class="user-card">
<div class="user-card-head"></div>
<div class="user-card-body">
<div class="user-card-body-left">
<img src="static/images/info.jpg">
</div>
<div class="user-card-body-right">
<div class="user-card-body-right-text">
<div class="user-card-body-right-text-username">
藜麦小笼包
<span>LV5</span>
</div>
<div class="user-card-body-right-text-reputation">
<span class="user-card-body-right-text-reputation-item">
<span>58</span>
<span>关注</span>
</span>
<span class="user-card-body-right-text-reputation-item">
<span>3</span>
<span>粉丝</span>
</span>
<span class="user-card-body-right-text-reputation-item">
<span>15</span>
<span>赞</span>
</span>
</div>
</div>
<div class="user-card-body-right-button">
<button>+关注</button>
<button>发消息</button>
</div>
</div>
</div>
</div>
<!--可以多复制几个,横向排列-->
</body>
</html>
style.css
.user-card {
width: 366px;
height: 215px;
box-shadow: 2px 2px 5px lightgray;
border-radius: 5px;
display: inline-block;
}
.user-card-head {
background-image: url('/Web/static/images/mountain.jpg');
background-size: cover;
width: 100%;
height: 85px;
}
.user-card-body {
width: 100%;
height: calc(100% - 85px);
box-sizing: border-box;
padding-top: 12px;
}
.user-card-body-left {
width: 70px;
height: 100%;
float: left;
text-align: center;
}
.user-card-body-right {
width: calc(100% - 70px);
height: 100%;
float: left;
}
.user-card-body-left>img {
width: 48px;
height: 48px;
border-radius: 50%;
}
.user-card-body-right-text {
width: 100%;
height: 70%;
}
.user-card-body-right-text-username {
padding-left: 10px;
font-size: 16px;
color: #222222;
font-weight: bold;
}
.user-card-body-right-text-username>span {
font-size: 12px;
color: #8BD29B;
font-style: italic;
}
.user-card-body-right-text-reputation {
padding-left: 10px;
padding-top: 12px;
box-sizing: border-box;
}
.user-card-body-right-text-reputation-item {
margin-right: 20px;
}
.user-card-body-right-text-reputation-item>span:nth-child(1) {
font-size: 12px;
color: #222222;
font-weight: 500;
}
.user-card-body-right-text-reputation-item>span:nth-child(2) {
font-size: 12px;
color: #9499A0;
}
.user-card-body-right-button {
padding-left: 10px;
}
.user-card-body-right-button>button {
width: 102px;
height: 30px;
border: none;
border-radius: 5px;
margin-right: 5px;
cursor: pointer;
}
.user-card-body-right-button>button:nth-child(1) {
background-color: #00A1D6;
color: white;
}
.user-card-body-right-button>button:nth-child(1):hover {
background-color: #00B5E5;
transition: 700ms;
}
.user-card-body-right-button>button:nth-child(2) {
background-color: white;
border: #CCD0D7 solid 1px;
color: #6D757A;
}
.user-card-body-right-button>button:nth-child(2):hover {
border-color: #00B5E5;
color: #00B5E5;
transition: 700ms;
}