<!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>
<!-- 1.引入样式表 2、调用类名 -->
<link rel="stylesheet" href="./iconfont/iconfont.css">
<style>
.icon-shequhuodong {
font-size: 200px;
color: red;
}
.icon-xihuan {
font-size: 50px;
}
</style>
</head>
<body>
<!-- iconfont是固定的 -->
<span class="iconfont icon-shequhuodong"></span>
<span class="iconfont icon-xihuan"></span>
</body>
</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>位移的基本使用</title>
<style>
.father {
width: 500px;
height: 300px;
border: 1px solid #000;
margin: 200px auto;
}
.son {
width: 200px;
height: 100px;
background-color: pink;
transition: all 1s;
}
.father:hover .son {
transform: translate(100px,100px);
/* 百分比:参考盒子自身的尺寸计算结果 */
transform: translate(-50%,-100%);
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
**transform: translate(100px,100px);效果**
transform: translate(-50%,-100%);效果
双开门代码
<!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>
* {
margin: 0;
padding: 0;
}
.box {
width: 1366px;
height: 600px;
margin: 0 auto;
background: url(./images/bg.jpg);
overflow: hidden;
}
.box::before,
.box::after {
float: left;
content: '';
width: 50%;
height: 100%;
background-image: url(./images/fm.jpg);
transition: all 3s;
}
.box::after {
/* 背景图右半边 */
background-position: right 0;
}
/* 鼠标移入的时候的位置改变的效果 before向左挪动,after向右挪动 */
.box:hover::before {
transform: translate(-100%);
}
.box.box:hover::after {
transform: translate(100%);
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
</html>
伪元素是行内显示模式
旋转需要配合过渡(transition)使用
多重转换
<!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 {
width: 800px;
height: 200px;
border: 1px solid #000;
margin: 30px auto;
}
img {
height: 200px;
transition: all 5s;
}
img:hover {
/* 旋转会改变坐标轴向 所以tanslate和rotate不能调换顺序*/
/* 旋转先改变了坐标轴向,位移方向会受影响 所以多重转换涉及到旋转到最后再添加该属性 */
transform: translate(600px) rotate(360deg);
}
</style>
</head>
<body>
<div class="box">
<img src="./tyre.png" alt="">
</div>
</body>
</html>
/* 透明到半透明名渐变 */
background-image: linear-gradient(
transparent,
rgba(0,0,0,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>华为新闻</title>
<link rel="stylesheet" href="./iconfont/iconfont.css">
<link rel="stylesheet" href="./CSS/综合案例.css">
</head>
<body>
<div class="box">
<ul>
<li>
<a href="#">
<div class="pic">
<img src="./images/product.jpeg" alt="">
</div>
<div class="txt">
<h4>产品</h4>
<h5>OceanStor Pacific 海量存储斩获2021 Interop金奖</h5>
<p>
<span>了解更多</span>
<i class="iconfont icon-arrow-right"></i>
</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="pic">
<img src="./images/huawei1.jpeg" alt="">
</div>
<div class="txt">
<h4>行业洞察</h4>
<h5>迈向智能世界2030</h5>
<p>
<span>了解更多</span>
<i class="iconfont icon-arrow-right"></i>
</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="pic">
<img src="./images/huawei2.jpeg" alt="">
</div>
<div class="txt">
<h4>《ICT新视界》刊首语</h4>
<h5>笃行致远,共建具有获得感、幸福感、安全感的智慧城市</h5>
<p>
<span>了解更多</span>
<i class="iconfont icon-arrow-right"></i>
</p>
</div>
</a>
</li>
</ul>
</div>
</body>
</html>
样式表
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
img {
width: 100%;
vertical-align: middle;
}
.box {
width: 1110px;
height: 247px;
margin: 20px auto;
/* background-color: pink; */
}
.box li {
position: relative;
float: left;
width: 350px;
height: 247px;
margin-right: 30px;
overflow: hidden;
}
.box li:last-child {
margin-right: 0;
}
.box .txt {
position: absolute;
left: 0;
bottom: -50px;
width: 350px;
height: auto;
padding: 20px 30px;
z-index: 1;
color: #fff;
transition: transform .5s;
/* transition: all .5s; */
}
.box .txt h4 {
font-size: 14px;
font-weight: 400;
line-height: 2em;
color: #fff;
}
.box .txt h5 {
margin-bottom: 40px;
font-size: 18px;
line-height: 1.5em;
color: #fff;
}
.box .txt p {
color: #fff;
font-size: 14px;
}
.box .txt p .iconfont {
color: #c7000b;
vertical-align: middle;
font-size: 20px;
font-weight: 700;
}
/* 1.字体图标 引入样式表,调用类名
2.渐变背景 书写盒子控制位置 hover显示
3.图片的缩放
4.文字位移 */
/* 渐变背景 */
.box li a::after{
position: absolute;
left: 0;
top: 0;
width: 350px;
height: 247px;
background-image: linear-gradient(
transparent,
rgba(0,0,0,.6)
);
opacity: 0;
transition: all .5s;
}
.box li:hover a::after {
opacity: 1;
}
.box li .pic img {
transition: all 0.5s;
}
/* 图片缩放 */
.box li:hover .pic img {
transform: scale(1.2);
}
/* 文字效果 */
.box li:hover .txt {
transform: translateY(-50px);
}
效果图