效果预览

按下右侧的“点击预览”按钮可以在当前页面预览,点击链接可以全屏预览。

https://codepen.io/comehope/pen/WgdVyx/

可交互视频

此视频是可以交互的,你可以随时暂停视频,编辑视频中的代码。

请用 chrome, safari, edge 打开观看。

https://scrimba.com/p/pEgDAM/c23zLuN

源代码下载

每日前端实战系列的全部源代码请从 github 下载:

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));
}
}

最后,不要忘记删掉辅助线。

大功告成!

前端每日实战:132# 视频演示如何用纯 CSS 创作一只思考的手的更多相关文章

  1. 前端每日实战:98# 视频演示如何用纯 CSS 创作一只愤怒小鸟中的绿猪

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/VBGWqX 可交互视频 此视频是可 ...

  2. 前端每日实战:124# 视频演示如何用纯 CSS 创作一只纸鹤

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xagoYb 可交互视频 此视频是可 ...

  3. 前端每日实战:103# 视频演示如何用纯 CSS 创作一只监视眼

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/GBzLdy 可交互视频 此视频是可 ...

  4. 前端每日实战:58# 视频演示如何用纯 CSS 创作一只卡通鹦鹉

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vrRmWy 可交互视频 此视频是可 ...

  5. 前端每日实战:73# 视频演示如何用纯 CSS 创作一只卡通狐狸

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OEKZed 可交互视频 此视频是可 ...

  6. 前端每日实战:111# 视频演示如何用纯 CSS 创作一只艺术的鸭子

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/aaoveW 可交互视频 此视频是可 ...

  7. 前端每日实战:70# 视频演示如何用纯 CSS 创作一只徘徊的果冻怪兽

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/VdOKQG 可交互视频 此视频是可 ...

  8. 前端每日实战:61# 视频演示如何用纯 CSS 创作一只咖啡壶

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ZRjGGy 可交互视频 此视频是可 ...

  9. 前端每日实战:62# 视频演示如何用纯 CSS 创作一只蒸锅

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/YvOzNy 可交互视频 此视频是可 ...

随机推荐

  1. WMS出库单重复

    发货通知单?WMS备货单选项勾选 不自动复制?新增?

  2. c/c++[001]:start

    作为一个学校课程跳过c语言的萌新,这次重新学习c/c++从源头上明白这两种不同的输入输出还是很有必要 scanf()是C语言中的一个输入函数.与printf函数一样,都被声明在头文件stdio.h里, ...

  3. CNN Mini-Fashion数据集以及Pytorch初体验

    下载Fasion-MNIST数据集 Fashion-MNIST是一个替代原始的MNIST手写数字数据集的另一个图像数据集. 它是由Zalando(一家德国的时尚科技公司)旗下的研究部门提供.其涵盖了来 ...

  4. ionic3 发布订阅者模式实现

    在ionic3 中实现订阅发布模式,需要用到Events. Events下面有三个方法 events.subscribe()  订阅 events.publish()  发布 events.unsub ...

  5. RHEL安装神器EPEL

    什么是EPEL? EPEL的全称叫 Extra Packages for Enterprise Linux .EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS.Scie ...

  6. linux清除cache的方法

    1  Linux下内存占用多的原因 当linux第一次读取一个文件运行时,一份放到一片内存中cache起来,另一份放入运行程序的内存中,正常运行,当程序运行完,关闭了,cache中的那一分却没有释放, ...

  7. scala slick mysql 字段过多 tuple问题

    原同步服务正常,因需,对方单表新增字段,超过22条 sbt assembly 编译出错 too many elements for tuple: 26, allowed: 22 scala case ...

  8. 【转】mac os x配置adb命令的方法,苹果电脑设置adb命令的方法

    http://www.myexception.cn/operating-system/1636963.html 步骤如下: 1. 启动终端Terminal (如果当前用户文件夹下已有.bash_pro ...

  9. 安装VSCODE和typora黑屏

    工欲善其事必先利其器,本来是为了学git为了保存代码,然后网上一顿搜索研究之后发现,用git来保存笔记也不错,因为现在用的onenote搜索实在在在在是太不方便了,除了搜索不行,其他方面她还是很好的, ...

  10. chap1-HttpRequest测试类

    # HttpRequest测试类, 封装请求方法 import requests class HttpRequest: def http_request(self, url, method, data ...