如何使用纯CSS实现一只会动的手(附源码)
本篇文章给大家带来的内容是关于如何使用纯CSS实现一只会动的手(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
效果预览
源代码下载
https://github.com/comehope/front-end-daily-challenges
代码解读
定义 dom,容器中的 5 个 .finger
元素代表 5 根手指,.thumb
元素代表大拇指,.palm
元素代表手掌:
<div class="hand"> <span class="finger thumb"></span> <span class="finger"></span> <span class="finger"></span> <span class="finger"></span> <span class="finger"></span> <span class="palm"></span> </div>
居中显示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(white, lightcyan); }
定义容器尺寸,其中 outline
属性是辅助线:
.hand { width: 16em; height: 8em; font-size: 10px; outline: 1px dashed black; }
画出手掌:
.hand { position: relative; color: darksalmon; } .palm { position: absolute; width: 8em; height: 6em; background-color: currentColor; border-radius: 1em 4em; right: 0; }
画出大拇指的轮廓:
.thumb { position: absolute; width: 9.6em; height: 3.2em; background-color: currentColor; border-radius: 3em 2em 2em 1em; right: 0; bottom: 1em; transform-origin: calc(100% - 2em) 2em; transform: rotate(-20deg); border-bottom: 0.2em solid rgba(0, 0, 0, 0.1); border-left: 0.2em solid rgba(0, 0, 0, 0.1); }
画出大拇指上的指甲:
.thumb::before { content: ''; position: absolute; width: 1.9em; height: 1.9em; background-color: rgba(255, 255, 255, 0.3); border-radius: 60% 10% 10% 30%; bottom: -0.3em; left: 0.5em; border-right: 0.1em solid rgba(0, 0, 0, 0.1); }
画出食指靠近手掌的后半部分:
.finger:not(:first-child) { position: absolute; width: 6.4em; height: 3.5em; background-color: currentColor; right: 5.2em; bottom: 4em; transform-origin: 100% 2em; transform: rotate(10deg); }
画出食指的前半部分:
.finger:not(:first-child)::before { content: ''; position: absolute; width: 9em; height: 3em; background-color: currentColor; right: 4.2em; top: 0.2em; border-radius: 2em; transform-origin: calc(100% - 2em) 2em; transform: rotate(-60deg); }
为除大拇指以外其他 4 根手指设置下标变量,从食指到小指逐渐缩小并且颜色加深:
.finger:not(:first-child) { --scale: calc(1 - (5 - var(--n)) * 0.2); transform: rotate(10deg) scale(var(--scale)); filter: brightness(calc(100% - (5 - var(--n)) * 10%)); } .finger:nth-child(2) { --n: 2; } .finger:nth-child(3) { --n: 3; } .finger:nth-child(4) { --n: 4; } .finger:nth-child(5) { --n: 5; }
用伪元素画出手的阴影:
.hand::before { content: ''; position: absolute; width: 14em; height: 4.5em; background-color: black; border-radius: 4em 1em; top: 4em; filter: blur(1em) opacity(0.3); }
增加手指敲击桌面的动画效果:
.finger:not(:first-child) { animation: tap-upper 1.2s ease-in-out infinite; animation-delay: calc((var(--n) - 2) * 0.1s); } @keyframes tap-upper { 0%, 50%, 100% { transform: rotate(10deg) scale(var(--scale)); } 40% { transform: rotate(50deg) scale(var(--scale)); } }
最后,不要忘记删掉辅助线。
大功告成!
相关推荐:
以上是如何使用纯CSS实现一只会动的手(附源码)的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

在 Vue.js 中使用 Bootstrap 分为五个步骤:安装 Bootstrap。在 main.js 中导入 Bootstrap。直接在模板中使用 Bootstrap 组件。可选:自定义样式。可选:使用插件。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

在 Bootstrap 中插入图片有以下几种方法:直接插入图片,使用 HTML 的 img 标签。使用 Bootstrap 图像组件,可以提供响应式图片和更多样式。设置图片大小,使用 img-fluid 类可以使图片自适应。设置边框,使用 img-bordered 类。设置圆角,使用 img-rounded 类。设置阴影,使用 shadow 类。调整图片大小和位置,使用 CSS 样式。使用背景图片,使用 background-image CSS 属性。

创建 Bootstrap 分割线有两种方法:使用 标签,可创建水平分割线。使用 CSS border 属性,可创建自定义样式的分割线。

要设置 Bootstrap 框架,需要按照以下步骤:1. 通过 CDN 引用 Bootstrap 文件;2. 下载文件并将其托管在自己的服务器上;3. 在 HTML 中包含 Bootstrap 文件;4. 根据需要编译 Sass/Less;5. 导入定制文件(可选)。设置完成后,即可使用 Bootstrap 的网格系统、组件和样式创建响应式网站和应用程序。

要调整 Bootstrap 中元素大小,可以使用尺寸类,具体包括:调整宽度:.col-、.w-、.mw-调整高度:.h-、.min-h-、.max-h-

如何使用 Bootstrap 按钮?引入 Bootstrap CSS创建按钮元素并添加 Bootstrap 按钮类添加按钮文本
