有趣的CSS - 按钮文字上下滑动

目录

  • 整体效果
  • 核心代码
    • html 代码
    • css 部分代码
  • 完整代码如下
    • html 页面
    • css 样式
    • 页面渲染效果

整体效果

这个按钮效果主要使用 :hover 伪选择器以及 transition 过渡属性来实现两个子元素上下过渡的效果。

此效果可以在主入口按钮、详情或者更多等按钮处使用,增加一些鼠标的交互效果。


核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。

核心代码

html 代码

<button><span class="defalut">鼠标放上来</span><span class="hover">点我吧</span>
</button>

button 标签主体,包裹两个子元素 span ,分别为 .defalut.hover

css 部分代码

*{transition: .5s;
}
button{width: 110px;height: 42px;color: #ffffff;background-color: #457356;border: none;border-radius: 4px;cursor: pointer;transition: all 0.3s linear;position: relative;overflow: hidden;
}
.defalut,.hover{width: 100%;height: 100%;line-height: 42px;letter-spacing: 2px;display: block;transition: all 0.3s ease-in-out;cursor: pointer;
}
.hover{position: absolute;left: 0;top: 100%;
}
button:hover .defalut{transform: translateY(-100%);
}
button:hover .hover{top: 0;
}

css 部分主要通过 :hover 伪选择器来分别设置两个 span 子元素的样式,然后配合 transform 以及定位来实现两个 span 的上下移动。

注意:全局定义了 transition: .5s


完整代码如下

html 页面

<!DOCTYPE html>
<html lang="zh"><head><meta charset="utf-8"><link rel="stylesheet" href="style.css"><title>按钮文字上下滑动</title></head><body><div class="app"><button><span class="defalut">鼠标放上来</span><span class="hover">点我吧</span></button></div></body>
</html>

css 样式

/** style.css **/
*{margin: 0;padding: 0;list-style: none;transition: .5s;
}
html,body{background-color: #efefef;color: #fff;font-size: 14px;
}
.app{width: 100%;height: 100vh;position: relative;display: flex;justify-content: center;align-items: center;
}
button{width: 110px;height: 42px;color: #ffffff;background-color: #457356;border: none;border-radius: 4px;cursor: pointer;transition: all 0.3s linear;position: relative;overflow: hidden;
}
.defalut,.hover{width: 100%;height: 100%;line-height: 42px;letter-spacing: 2px;display: block;transition: all 0.3s ease-in-out;cursor: pointer;
}
.hover{position: absolute;left: 0;top: 100%;
}
button:hover .defalut{transform: translateY(-100%);
}
button:hover .hover{top: 0;
}

页面渲染效果

以上就是所有代码,以及简单的思路,希望对你有一些帮助或者启发。


[1] 原文阅读

我是 Just,这里是「设计师工作日常」,求点赞求关注!skr~ skr~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/455432.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

zxxxxczzvdsgbhfdb

欢迎关注博主 Mindtechnist 或加入【Linux C/C/Python社区】一起探讨和分享Linux C/C/Python/Shell编程、机器人技术、机器学习、机器视觉、嵌入式AI相关领域的知识和技术。 磁盘满的本质分析 专栏&#xff1a;《Linux从小白到大神》 | 系统学习Linux开发、VIM/GCC/GDB/Make工具…

Flink 动态表 (Dynamic Table) 解读

博主历时三年精心创作的《大数据平台架构与原型实现&#xff1a;数据中台建设实战》一书现已由知名IT图书品牌电子工业出版社博文视点出版发行&#xff0c;点击《重磅推荐&#xff1a;建大数据平台太难了&#xff01;给我发个工程原型吧&#xff01;》了解图书详情&#xff0c;…

深度解析ScheduledThreadPoolExecutor源码之ScheduledFutureTask

文章目录 引言一、RunnableScheduledFuture定义周期性接口二、ScheduledFutureTask源码分析2.1 ScheduledFutureTask参数解析2.2 ScheduledFutureTask源码方法解析 总结 引言 在上一章节我们已经对ScheduledThreadPoolExecutor中的延迟队列DelayedWorkQueue做了源码分析深度解…

ManimCE教程(1)快速入门

概述 Manim 是一个用于精确编程动画的动画引擎。 开始一个新项目 首先创建一个新文件夹&#xff0c;命名为&#xff1a;project&#xff0c;此文件夹是项目的根文件夹&#xff0c;它包含 Manim 运行所需的所有文件&#xff0c;以及项目产生的所有输出。 设置圆的动画 1、打…

文心一言4.0API接入指南

概述 文心一言是百度打造出来的人工智能大语言模型&#xff0c;具备跨模态、跨语言的深度语义理解与生成能力&#xff0c;文心一言有五大能力&#xff0c;文学创作、商业文案创作、数理逻辑推算、中文理解、多模态生成&#xff0c;其在搜索问答、内容创作生成、智能办公等众多…

Python入门:常用模块—time datetime模块

在python中&#xff0c;与时间处理有关的常用模块有&#xff1a;time&#xff0c;datetime&#xff0c;calendar&#xff08;很少用&#xff09; 一、在Python中&#xff0c;通常有这几种方式来表示时间&#xff1a; 时间戳格式化的时间字符串元组&#xff08;struct_time&am…

vscode 突然连接不上服务器了(2024年版本 自动更新从1.85-1.86)

vscode日志 ll192.168.103.5s password:]0;C:\WINDOWS\System32\cmd.exe [17:09:16.886] Got some output, clearing connection timeout [17:09:16.887] Showing password prompt [17:09:19.688] Got password response [17:09:19.688] "install" wrote data to te…

centos7编译安装redis

一、环境 系统&#xff1a;CentOS Linux release 7.9.2009 (Core) redis版本&#xff1a;redis 6.0.6 二、安装及部署 当前最新稳定版本是redis 6.0.6 国内网址&#xff1a;http://www.redis.cn redis下载列表&#xff1a;http://download.redis.io/releases/ 下载 wge…

肿瘤免疫分型

Elements of cancer immunity and the cancer-immune set point - PubMed (nih.gov) Daniel S Chen , Ira Mellman 人类的抗癌免疫可分为三种主要表型&#xff1a;免疫沙漠表型&#xff08;棕色&#xff09;、免疫排除表型&#xff08;蓝色&#xff09;和免疫炎症型&#xff0…

一般系统的请求认证授权思路【gateway网关+jwt+redis+请求头httpheader】

gateway&#xff1a;网关&#xff0c;我们都知道网关的作用就是对系统的所有请求&#xff0c;网关都会进行拦截&#xff0c;然后做一些操作&#xff08;例如&#xff1a;设置每个请求的请求头httpHeader&#xff0c;身份认证等等&#xff09;此时一般会使用到网关过滤器&#x…

JenkinsGitLab完成自动化构建部署

关于GitLab安装:GitLab安装-CSDN博客 Docker中安装GitLab:Docker下安装GitLab-CSDN博客 安装JenKins Jenkins官网:Jenkins 中文版:Jenkins 安装时候中文页面的war包下不来 在英文页面 记得装JDK8以上 JenKins使用java写的 运行JenKins需要JDK环境 我这里已经装好了 将下…

【工具】Android|Android Studio 长颈鹿版本安装下载使用详解

版本&#xff1a;2022.3.1.22&#xff0c; https://redirector.gvt1.com/edgedl/android/studio/install/2022.3.1.22/android-studio-2022.3.1.22-windows.exe 前言 笔者曾多次安装并卸载Android Studio&#xff0c;反复被安卓模拟器劝退。现在差不多是第三次安装&#xff0c…