CSS笔记补充
1.过渡效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>过渡效果</title>
</head>
<style>
.box1 {
width: 100px;
height: 100px;
background-color: black;
transition-property: all;
transition-duration: 10s;
transition-timing-function: ease;
}
.box1:hover {
width: 200px;
height: 200px;
background-color: rebeccapurple;
}
.box2 {
width: 100px;
height: 100px;
background-color: yellowgreen;
border-radius: 50px;
transition: all 2s ease-in;
margin: 20px auto;
}
.box2:hover {
width: 200px;
height: 200px;
background-color: red;
border-radius: 100px;
}
</style>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
2.动画效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动画效果</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
.box1 {
width: 600px;
height: 600px;
border: 5px solid black;
margin: 10px auto;
position: relative;
}
.box2 {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
animation-name: move1;
animation-duration: 10s;
animation-timing-function: ease;
animation-iteration-count: infinite;
animation-direction: alternate-reverse;
animation-play-state: running;
}
.box2:hover {
animation-play-state: paused;
}
@keyframes move1 {
0% {
left: 0;
top: 0;
}
25% {
left: 500px;
top: 0;
}
50% {
left: 500px;
top: 500px;
}
75% {
left: 0;
top: 500px;
}
100% {
left: 0;
top: 0;
}
}
</style>
<body>
<div class="box1">
<div class="box2"></div>
</div>
</body>
</html>
3.轮播图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 1080px;
height: 420px;
margin: 20px auto;
border: 1px solid black;
overflow: hidden;
position: relative;
}
.list {
width: 5400px;
height: 420px;
position: absolute;
top: 0px;
left: 0px;
animation: move1 8s 1s infinite steps(4);
}
.list img {
float: left;
}
@keyframes move1 {
from {
left: 0px;
}
to {
left: -4320px;
}
}
</style>
</head>
<body>
<div>
<div class="box">
<div class="list">
<img src="img/a.jpg" alt="">
<img src="img/b.jfif" alt="">
<img src="img/c.jfif" alt="">
<img src="img/d.jpeg" alt="">
<img src="img/a.jpg" alt="">
</div>
</div>
</div>
</body>
</html>
4.变形效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>变形效果</title>
<style>
.box {
width: 200px;
height: 200px;
background-color: black;
margin: 0px auto;
transition: all 1s;
}
.box:hover {
transform: scale(1.5) rotate(360deg) skew(30deg);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
flex布局
1.弹性盒子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>弹性盒子</title>
<style>
.box1 {
border: 5px solid #000;
display: flex;
}
.box2 {
border: 5px solid #000;
margin-top: 10px;
display: flex;
justify-content: space-around;
align-items: baseline;
flex-direction: column;
}
.a {
width: 100px;
height: 100px;
background-color: red;
}
.b {
width: 150px;
height: 150px;
background-color: blue;
}
.c {
width: 100px;
height: 100px;
background-color: yellowgreen;
}
.d {
width: 200px;
height: 200px;
background-color: brown;
}
</style>
</head>
<body>
<div class="box1">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
</div>
<div class="box2">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
</div>
</body>
</html>
2.弹性盒子换行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>弹性盒子换行</title>
<style>
.box {
border: 5px solid blueviolet;
height: 600px;
width: 1200px;
display: flex;
flex-wrap: wrap;
align-content: space-evenly;
}
.box div {
width: 120px;
height: 120px;
box-shadow: 0px 0px 2px lightcoral;
}
</style>
</head>
<body>
<div class="box">
<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>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
<div>21</div>
<div>22</div>
<div>23</div>
<div>24</div>
<div>25</div>
<div>26</div>
<div>27</div>
<div>28</div>
<div>29</div>
<div>30</div>
</div>
</body>
</html>
3.下拉菜单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0px;
padding: 0px;
list-style: none;
text-decoration: none;
}
header {
width: 800px;
height: 50px;
margin: 10px auto;
background: linear-gradient(to left top, #F761A1, #8C1BAB);
}
nav {
position: relative;
align-items: stretch;
}
nav ul {
display: flex;
justify-content: space-evenly;
}
nav ul li {
margin-top: 10px;
font-size: 20px;
font-weight: bold;
}
nav ul li a {
color: wheat;
}
.one {
width: 80px;
height: 125px;
background-color: #8C1BAB;
position: absolute;
top: 50px;
right: 175px;
color: white;
text-align: center;
line-height: 30px;
font-size: 18px;
display: none;
}
.two {
width: 100px;
height: 100px;
background-color: blue;
text-align: center;
line-height: 32px;
position: absolute;
top: 50px;
left: 300px;
display: none;
}
a:active .one,
a:active .two {
display: block;
}
</style>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="">首页</a></li>
<li><a href="">列表</a></li>
<li>
<a href="">新闻
<div class="two">
<p>国内新闻</p>
<p>国内新闻</p>
<p>国内新闻</p>
</div>
</a>
</li>
<li><a href="">咨询</a></li>
<li>
<a href="">体育
<div class="one">
<p>英超</p>
<p>英超</p>
<p>英超</p>
<p>英超</p>
<p>英超</p>
</div>
</a>
</li>
<li><a href="">娱乐</a></li>
</ul>
</nav>
</header>
</body>
</html>
3.align-self属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
height: 300px;
padding: 10px;
border: 5px solid black;
justify-content: space-evenly;
align-items: center;
}
.box div {
height: 100px;
width: 300px;
border: 5px solid #ccc;
text-align: center;
line-height: 100px;
font-size: 30px;
font-weight: bold;
}
div:last-of-type {
align-self: flex-end;
}
</style>
</head>
<body>
<div class="box">
<div>张靓颖</div>
<div>邓紫棋</div>
<div>吴宣仪</div>
<div>张静怡</div>
</div>
</body>
</html>
4. flex属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
height: 100px;
padding: 10px;
border: 5px solid black;
justify-content: space-evenly;
}
.box div {
height: 100px;
border: 5px solid #ccc;
text-align: center;
line-height: 100px;
font-size: 30px;
font-weight: bold;
}
div:nth-of-type(1) {
flex: 1;
}
</style>
</head>
<body>
<div class="box">
<div>张靓颖</div>
<div>邓紫棋</div>
<div>吴宣仪</div>
<div>张静怡</div>
</div>
</body>
</html>
5. Order属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
height: 100px;
padding: 10px;
border: 5px solid black;
justify-content: space-evenly;
}
.box div {
width: 100px;
border: 5px solid #ccc;
text-align: center;
line-height: 80px;
}
.box div:first-of-type {
order: 4;
}
.box div:nth-of-type(2) {
order: 1;
}
.box div:nth-of-type(3) {
order: 3;
}
.box div:nth-of-type(4) {
order: 2;
}
</style>
</head>
<body>
<div class="box">
<div>张靓颖</div>
<div>邓紫棋</div>
<div>吴宣仪</div>
<div>张静怡</div>
</div>
</body>
</html>
grid布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
border: 2px solid black;
display: grid;
grid: 160px 200px 150px/ 200px 300px 300px;
}
.box div {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="box">
<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>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>grid布局2</title>
<style>
.box {
border: 5px solid black;
width: 1000px;
height: 600px;
margin: 0px auto;
display: grid;
grid: "b b . . ."
"b b . . ."
" . . . a a"
" . . . a a";
grid-gap: 10px;
padding: 10px;
}
.box div {
border: 1px solid skyblue;
padding: 10px;
}
div:first-of-type {
grid-area: b;
}
div:nth-of-type(2) {
grid-area: a;
}
</style>
</head>
<body>
<div class="box">
<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>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
</div>
</body>
</html>