首页 技术 正文
技术 2022年11月7日
0 收藏 680 点赞 703 浏览 1720 个字

原文地址1# 视频演示如何用纯 CSS 创作一个按钮文字滑动特效

扩展后地址:https://scrimba.com/c/cJkzMfd

HTML代码:

<html>
<head>
<link rel="stylesheet" href="index.css" rel="external nofollow" >
</head>
<body>
<div class="animation">唉,没有啥新想法添加。。。</div>
<div class="box">
<span data-text="B">B</span>
<span data-text="U">U</span>
<span data-text="T">T</span>
<span data-text="T">T</span>
<span data-text="O">O</span>
<span data-text="N">N</span>
</div>
<script src="index.pack.js"></script>
<script>
/* alert("唉,没有啥新想法添加。。。"); */
</script>
</body>
</html>

css代码:

.animation{
position: absolute;
top:0px;
/* 让字体位于窗口顶部右边外围 这里的数据是死的*/
right: -210px;
/*
规定动画的名称
规定动画的时长
规定动画的次数
*/
animation:mymove 10s infinite;
animation-delay:0s; /*Safari and Chrome 兼容*/
-webkit-animation:mymove 10s infinite;
-webkit-animation-delay:0s;
}
@keyframes mymove{
from {
left:100%;
}
to {
left:-200px;
}
}
@-webkit-keyframes mymove /*Safari and Chrome*/{
from {left:100%;}
to {left:-200px;}
}/* 按钮居中 */
html, body {
margin:;
padding:;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
/* 对于超出的内容隐藏 */
overflow: hidden;
}
/* 设置按钮的尺寸和文字样式 */
.box {
width: 200px;
height: 60px;
border: 2px solid black;
text-align: center;
font-size: 30px;
line-height: 60px;
font-family: sans-serif;
}
/* 按钮的每个字母都设置为行内块元素,以便单独设置动效 */
.box span {
display: inline-block;
color: blue;
}
/*把字母交错地显示在按钮容器之外,第奇数个元素显示在上,第偶数个元素显示在下:*/
.box span:nth-child(odd) {
/* Y轴向上平移自身高度单位 */
transform: translateY(-100%);
}
.box span:nth-child(even) {
transform: translateY(100%);
}
/* 用伪元素为每个字母增加一个副本:*/
.box span::before {
/* attr 的解说 http://www.runoob.com/cssref/pr-gen-content.html */
content: attr(data-text);
position: absolute;
color: red;
}
/* 让伪元素的字母也交错显示,位置与其原始元素相对:*/
.box span:nth-child(odd)::before {
transform: translateY(100%);
}
.box span:nth-child(even)::before {
transform: translateY(-100%);
}
/* 为按钮增加鼠标划过样式,设置緩动时间,使其有动画效果:*/
.box:hover span {
transform: translateY(0);
}
.box span {
transition: 1s;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,484
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,899
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,732
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,485
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,125
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,286