一、使用flexbox实现居中布局
要求:创建一个包含多个元素的容器。
使用 Flexbox 确保这些元素在水平和垂直方向上都居中。
<!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>flex居中布局</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.father {
display: flex;
width: 300px;
height: 300px;
justify-content: center;
align-items: center;
background-color: pink;
margin: 100px auto;
}
.son {
width: 100px;
height: 100px;
background-color: #fff;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
二、实现一条0.5像素的竖线/横线。
要求:实现一条0.5像素的竖线/横线。
<!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>实现0.5线</title>
<style>
.line {
position: absolute;
left: 0;
top: 10px;
width: 100%;
height: 1px;
background-color: #000000;
transform: scaleY(.5);
}
.line1 {
position: relative;
top: 20px;
width: 100%;
height: 1px;
background-color: #000000;
}
</style>
</head>
<body>
<div class="line"></div>
<div class="line1"></div>
</body>
</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>呼吸效果渐变</title>
<style>
.container {
width: 50px;
height: 50px;
z-index: 999;
position: absolute;
bottom: 20px;
right: 10px;
background-color: #ff5c33;
color: #ffffff;
border-radius: 50%;
text-align: center;
line-height: 50px;
cursor: pointer;
-webkit-animation: mymove 1s 1, mymovecolor 3s linear 1s infinite normal;
animation: mymove 1s 1, mymovecolor 3s linear 1s infinite normal;
display: table;
border: 8px solid #ffffff;
}
@keyframes mymove {
from {
bottom: 0;
}
to {
bottom: 20px;
}
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes mymovecolor {
50% {
background-color: #ff5c33;
}
50% {
border: 8px solid #f3967e;
}
}
</style>
</head>
<body>
<div class="container">
加入
</div>
</body>
</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>鼠标悬停阴影效果</title>
<style>
.box {
margin-left: 200px;
margin-top: 200px;
width: 200px;
height: 200px;
background-color: pink;
}
.box:hover {
box-shadow: 10px 10px 15px 0 rgba(0, 0, 0, 0.24);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>