当前位置: 首页 > news >正文

HTML+CSS 彩色浮雕按钮

效果演示

25-彩色浮雕按钮.gif

实现了一个彩色按钮特效,包括一个按钮(button)和一个前景色(::before)。按钮具有四种不同的颜色,当鼠标悬停在按钮上时,前景色会出现渐变效果,并且按钮的颜色、文本阴影和边框阴影会发生变化。整个按钮具有立体感,使其看起来更加美观。

Code

HTML
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>彩色浮雕按钮</title><link rel="stylesheet" href="./25-彩色浮雕按钮.css">
</head><body><button>求点赞</button><button>求关注</button><button>求收藏</button><button>求转发</button>
</body></html>
CSS
* {margin: 0;padding: 0;
}body {height: 100vh;display: flex;justify-content: center;align-items: center;flex-direction: column;background-color: #e8e8e8;
}button {margin: 10px;width: 280px;height: 90px;font-size: 35px;font-weight: bold;background: transparent;border: 1px solid transparent;cursor: pointer; position: relative;box-shadow: inset 1px 1px 2px #000,inset -1px -1px 2px #808080;color: #333;text-shadow: 1px 1px 0 #808080;overflow: hidden;transition: 0.3s linear 0.15s;
}button:nth-child(1) {--c: #ff4757;
}button:nth-child(2) {--c: #ffa502;
}button:nth-child(3) {--c: #2ed573;
}button:nth-child(4) {--c: #1e90ff;
}button::before {content: "";position: absolute;width: 100px;height: 8px;top: 0;left: 50%;transform: translateX(-50%);border-radius: 0 0 50% 50%;filter: blur(5px);transition: 0.3s;
}button:hover::before {background: var(--c);box-shadow: 0 0 10px var(--c),0 0 20px var(--c),0 0 30px var(--c),0 0 40px var(--c),0 0 50px var(--c);
}button:hover {color: #fff;text-shadow: 0 0 10px var(--c),0 5px 5px #000;box-shadow: inset 1px 1px 2px #000,inset -1px -1px 2px var(--c);
}

实现思路拆分

好的,下面是每行代码的详细讲解及注释:

* {margin: 0;padding: 0;
}

这段代码是设置所有元素的外边距和内边距为0。

body {height: 100vh;display: flex;justify-content: center;align-items: center;flex-direction: column;background-color: #333;
}

这段代码是设置body元素的高度为100vh,使用flex布局,使其水平和垂直居中。同时设置flex-direction为column,使其内部元素垂直排列。并且设置背景颜色为#333。

button {margin: 10px;width: 280px;height: 90px;font-size: 35px;font-weight: bold;background: transparent;border: 1px solid transparent;position: relative;box-shadow: inset 1px 1px 2px #000,inset -1px -1px 2px #808080;color: #333;text-shadow: 1px 1px 0 #808080;overflow: hidden;transition: 0.3s linear 0.15s;
}

这段代码是设置按钮的样式。包括外边距、宽度、高度、字体大小、字体粗细、背景、边框、相对定位、内部阴影效果、字体颜色和文本阴影效果。并且设置过渡效果。

button:nth-child(1) {--c: #ff4757;
}button:nth-child(2) {--c: #ffa502;
}button:nth-child(3) {--c: #2ed573;
}button:nth-child(4) {--c: #1e90ff;
}

这段代码是为每个按钮设置不同的颜色。使用CSS变量(–c)来存储颜色值。

button::before {content: "";position: absolute;width: 100px;height: 8px;top: 0;left: 50%;transform: translateX(-50%);border-radius: 0 0 50% 50%;filter: blur(5px);transition: 0.3s;
}

这段代码是设置前景色的样式。使用伪元素::before,设置宽度、高度、相对定位、顶部和左侧偏移、圆角和模糊效果。并且设置过渡效果。

button:hover::before {background: var(--c);box-shadow: 0 0 10px var(--c),0 0 20px var(--c),0 0 30px var(--c),0 0 40px var(--c),0 0 50px var(--c);
}

这段代码是设置当鼠标悬停在按钮上时,前景色的渐变效果。使用:hover伪类,设置背景颜色和阴影效果。

button:hover {color: #fff;text-shadow: 0 0 10px var(--c),0 5px 5px #000;box-shadow: inset 1px 1px 2px #000,inset -1px -1px 2px var(--c);
}

这段代码是设置当鼠标悬停在按钮上时,按钮的颜色、文本阴影和边框阴影的变化。使用:hover伪类,设置字体颜色、文本阴影效果和内部阴影效果。

http://www.lryc.cn/news/383447.html

相关文章:

  • ChatBI开源实现: 基于SuperSonic的AI+BI的产品设计
  • 【嵌入式Linux】i.MX6ULL 外部中断服务函数的初始化
  • 线性代数、矩阵计算
  • PostgreSQL 高级功能(五)
  • 食品企业仓储式批发零售一体化解决方案
  • chrome插件,修改对应URL的http请求的header头,包括ajax请求
  • C语言 | Leetcode C语言题解之第191题位1的个数
  • 【C++11(二)】lambda表达式和可变参数模板
  • 昇思25天学习打卡营第2天|张量Tensor
  • [leetcode]valid-triangle-number. 有效三角形的个数
  • java SQL server 多实例的情况
  • html--404页面
  • [word] Word如何删除所有的空行? #职场发展#学习方法
  • 【CSS】深入探讨 CSS 的 `calc()` 函数
  • MongoDB异地备份数据文件脚本(带日志打印,便于排查)
  • 论文导读 | Manufacturing Service Operations Management近期文章精选
  • 【Linux命令】top linux下的任务管理器
  • 2024年在分数限制下,选好专业还是选好学校?
  • cropperjs 裁剪/框选图片
  • ArkTS开发系列之事件(2.8.2手势事件)
  • 【MATLAB源码-第135期】基于matlab的变色龙群优化算法CSA)机器人栅格路径规划,输出做短路径图和适应度曲线。
  • 使用Python实现深度学习模型:语言模型与文本生成
  • 大数据面试题之Hive(3)
  • 华为OD机考题HJ17 坐标移动
  • redis修改密码
  • 《昇思 25 天学习打卡营第 7 天 | 模型训练 》
  • HTML/CSS 基础
  • Linux系统安装Lua语言及Lua外部库
  • 前端技术栈学习:Vue2、Vue cli脚手架、ElementUI组件库、Axios
  • pycharm中取消Typo:In word ‘xxx‘提示(绿色波浪线提示)的方法