前言:哈喽,大家好,今天给大家分享html+css 绚丽效果!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕
目录
一、效果
二、原理解析
1.这是一个,图片分多层的效果。每个按钮都是由5部分组成,组成:1个div,4个img,如下图。
2.当按钮上有鼠标时,hover效果触发,运行transition过渡动画效果。
.imgWrap:hover img:nth-child(4){
transform: translate(120px, -120px); /* 这一部分的值是如何思考,构成整个图案的*/
opacity: 1;
}
.imgWrap:hover img:nth-child(3){
transform: translate(90px, -90px);
opacity: 0.8;
}
.imgWrap:hover img:nth-child(2){
transform: translate(60px, -60px);
opacity: 0.6;
}
.imgWrap:hover img:nth-child(1){
transform: translate(30px, -30px);
opacity: 0.4;
}
a:hover span {
color: #fff;
}
a:hover {
background: #dd4b39;
}
a:hover:before {
background: #b33a2b;
}
a:hover:after {
background: #e66a5a;
}
3.具体的变换参数,直接看代码,可以一键复制,查看效果
三、上代码,可以直接复制使用
目录
img
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>html+css 实现hover 3D图片分层效果</title>
<link rel="stylesheet" href="https://at.alicdn.com/t/c/font_4646876_7vpdpyxzi9o.css">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="container">
<h1 style="text-align: center;color:#fff;margin-bottom: 50px;padding-top: 50px; text-shadow: 0 3px 3px #4c6ed3;">
html+css 实现hover 3D图片分层效果</h1>
<div class="wrapper">
<div class="imgWrap">
<img src="./img.jpeg">
<img src="./img.jpeg">
<img src="./img.jpeg">
<img src="./img.jpeg">
</div>
</div>
</div>
</body>
</html>
css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--btn-bg-color: #fff;
--font-color-black: #000;
--btn-bg-color-hover: #FF5833;
}
.wrapper {
margin-top: 130px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 40px;
}
.imgWrap{
cursor: pointer;
position: relative;
width: 250px;
height: 535px;
background: rgba(0,0,0,0.1);
transform: rotate(-30deg) skew(25deg); /*角度设置初步具有3d效果*/
transition: 0.5s;
}
.imgWrap img{
position: absolute;
width: 100%;
transition: 0.5s;
}
.imgWrap:hover img:nth-child(4){
transform: translate(120px, -120px); /* 这一部分的值是如何思考,构成整个图案的*/
opacity: 1;
}
.imgWrap:hover img:nth-child(3){
transform: translate(90px, -90px);
opacity: 0.8;
}
.imgWrap:hover img:nth-child(2){
transform: translate(60px, -60px);
opacity: 0.6;
}
.imgWrap:hover img:nth-child(1){
transform: translate(30px, -30px);
opacity: 0.4;
}
a:hover span {
color: #fff;
}
a:hover {
background: #dd4b39;
}
a:hover:before {
background: #b33a2b;
}
a:hover:after {
background: #e66a5a;
}
到此这篇文章就介绍到这了,更多精彩内容请关注本人以前的文章或继续浏览下面的文章,创作不易,如果能帮助到大家,希望大家多多支持宝码香车~💕
更多专栏订阅推荐:
👍 html+css+js 绚丽效果
💕 vue
✈️ Electron
⭐️ js
📝 字符串
✍️ 时间对象(Date())操作