自定义字体
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
/*自定义字体*/
@font-face {
font-family:"myfont01"; /*字体的名字,自定义*/
src: url(fonts/icomoon.ttf); /*文件夹名*/
src: url(fonts/icomoon.svg); /*依次寻找能用的字体,找到即不再往下扫描*/
src: url(./fonts/icomoon.woff);
src: url(fonts/icomoon.eot);
src: url(css/demo.css);
}
.s1{
font-family: "myfont01";
}
.s1::after{
content: "\e912";
font-size: 30px;
color: #FF0000;
}
</style>
</head>
<body>
<span class="s1">hello 中国 123!</span>
</body>
</html>
代码的运行结果:
遮罩效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>遮罩效果</title>
<style>
.pic{
width: 1000px;
height: 462px;
background-image: url(img/兰台小筑.jpg);
position: relative;
}/*外层设置相对,里层设置绝对*/
.pic:hover::after{
content: "";
width: 1000px;
height: 462px;
background-color: rgba(255,0,0,0.4); /*所有都为0是黑色*/
position: absolute;
left: 0;
top: 0;
}
.pic:hover::before{
content: "";
width: 1000px;
height: 462px;
background-image: url(img/播放.webp);
background-repeat: no-repeat;
background-position: center;
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div class="pic"></div>
</body>
</html>
代码的运行结果:
清除浮动
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>清除浮动</title>
<style>
div{
width: 400px;
height: 100px;
}
.d1{
background-color: red;
float: left;
}
/*.d2{
background-color: #7FFFD4;
clear: left;
}*//*第一种清除浮动的方式*/
.d2{
background-color: #7FFFD4;
}
.d2::after{
content: "";
clear: left;
display: block;
height: 0;
visibility: hidden;
}/*这种需要多加一个div*/
</style>
</head>
<body>
<div class="d1">11111</div>
<div></div>
<div class="d2">22222</div>
</body>
</html>
代码的运行结果:
Test——进度条
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>进度条</title>
<style>
.b1{
width: 1000px;
height: 100px;
border: 1px solid deepskyblue;
border-radius: 100px;
background-color: powderblue;
/*transition: all 10s linear;*/
}
/*.b1:hover>.b2{
border-radius: 100px;
width: 50%;
height: 100%;
background-color: red;
transition: all 10s linear;
}*/
.b2{
width: 0;
height: 100%;
border-radius: 100px;
background-color: red;
/*transition: all 1s linear;*/
}
.b1:hover>.b2{
width: 50%;
transition: all 1s linear;
}/*悬停谁给谁添加*/
</style>
</head>
<body>
<div class="b1">
<div class="b2"></div>
</div>
</body>
</html>
代码的效果:
悬浮之前:
悬浮之后:
父子元素清除浮动
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>父子两个元素-清除浮动</title>
<style>
.box{
width: 800px;
height: 300px;
border: 1px solid;
float: left;
}
/*.d1,.d2{
width: 200px;
height: 100px;
border: 1px solid black;
margin: 10px;
}*/
.box div{
width: 200px;
height: 100px;
border: 1px solid yellow;
margin: 10px;
}
.d1{
background-color: pink;
}
.d2{
background-color: greenyellow;
}
.box::after{
content: "";
clear: both;
}
</style>
</head>
<body>
<div class="box">
<!--before-->
<div class="d1">11111</div>
<div class="d2">22222</div>
<div>hellohellohellohellohellohellohello</div>
<!--after-->
</div>
<div>hellohellohellohellohellohellohello</div>
</body>
</html>
代码的运行结果:
模糊
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>模糊</title>
<style>
img:hover{
filter: blur(2px);
}
</style>
</head>
<body>
<img src="img/移动城堡.jpg" />
</body>
</html>
代码运行结果:
屏幕宽度-100px
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
div{
width: calc(50% - 100px);/*屏幕宽度-100px %后面必须有空格!!减号后面必须有空格!!*/
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
代码运行结果:
变色进度条
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
div{
width: 100px;
height: 40px;
background-color: red;
/*transition: width 1s linear ;
transition: background-color 1s linear;*/
transition: all 1s linear;
}/*linear匀速变化 ease-in加速 ease-in-out先加速后减速*/
div:hover{
width: 300px;
background-color: greenyellow;
border-radius: 100px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
代码的运行结果(不全):
最开始:
最终结果:
css2D效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css3的2D效果</title>
<style>
.box{
width: 800px;
height: 300px;
border: 1px solid;
}
.b1{
width: 50px;
height: 50px;
background-color: red;
}
.box:hover>.b1{
/*transform: translateX(500px);*//*平移*/
/*transform: translate(500px,200px);*/
/*transform: translate(500px,300px);*//*不影响其他模块*/
/*transform: rotate(360deg);*//*z轴旋转360度*/
/*transform: rotateX(360deg);*//*x轴*/
transform: rotateY(360deg);/*y轴*/
border-radius: 50px;*
transition: all 2s ease;
}
</style>
</head>
<body>
<div class="box">
<div class="b1"></div>
</div>
<!--旋转,遮罩,平移-->
</body>
</html>
代码的运行结果:
开始:
结束:
作业:css3选择器before与after应用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>css3选择器before与after应用</title>
<style>
*{ /*匹配所有标签*/
margin: 0;
padding: 0;
}
nav{
width: 80%;
height: 40px;
border:1px solid;
padding: 3px;
margin: 0 auto;
}
nav>ul{
background-color: aquamarine;
list-style: none;
overflow: hidden;/*溢出:隐藏 实现子层元素浮动,父元素高度无法撑开的问题*/
height: 100%;
line-height: 40px;/*一般不用百分比*/
}
nav>ul>li{
float: left;
width: 20%;
margin-left: 10%;
/*margin-right: 3px;*/
/*border: 1px solid red;*/
/*outline: 1px solid red;*/
text-align: center;
position: relative;
}
/*悬停效果:添加三角形*/
nav>ul>li:hover::before{
content:"";
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid transparent;
border-bottom: 10px solid red;
position: absolute;
left: 50%;
bottom: -2px;
margin-left: -10px;
}
</style>
</head>
<body>
<nav>
<ul>
<li>首页</li>
<li>个人中心</li>
<li>联系我们</li>
</ul>
</nav>
</body>
</html>
代码运行结果:
作业:遮罩效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>遮罩效果</title>
<style>
.pic{
width: 1066px;
height: 600px;
background-image: url(img/兰台小筑.jpg);
}
.cov{
width: 1066px;
height: 0;
background-color: rgba(0,0,0,0.4);
transition: all 3s ease-in;
}
.pic:hover>.cov{
height: 600px;
float: left;
transform: rotateY(360deg);
transition: all 3s ease;
}
</style>
</head>
<body>
<div class="pic">
<div class="cov"></div>
</div>
</body>
</html>
代码运行结果:
如果图片侵权,那我就删