效果预览

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

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. Hibernate/JPA中@Where使用时注意

    在使用Hibernate或者JPA时,我们经常会使用@Where注解实现查询过滤,在实体类上.实体属性上.查询语句上都有应用. 例如: @Where(clause = "status != ...

  2. P - Atlantis (线段树+扫描线)

      There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Som ...

  3. ios 设置UITextField的placeholder大小颜色

    需求:产品嫌弃placeholder的字体太大,颜色太明显,要求跟正常输入时的字体及颜色不同 方法:设置placeholder的大小和颜色,实际上是设置placeholder的label的大小和颜色, ...

  4. [LC] 125. Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  5. Python与数据库

    链接汇总 https://www.cnblogs.com/stacklike/category/1134822.html Python与数据库[1] -> 数据库接口/DB-API[0] -&g ...

  6. 3dmax2013卸载/安装失败/如何彻底卸载清除干净3dmax2013注册表和文件的方法

    3dmax2013提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装3dmax2013失败提示3dmax2013安装未完成,某些产品无法安装,也有时候想重新安装3 ...

  7. C语言返回值

    C语言函数在结束的时候可以用一个数字表示运行的结果,这个数字就叫做函数的返回值. 主函数应该有一个返回值.如果这个返回值是0就表示程序希望计算机认为它正常结束,如果不是0就表示程序希望计算机认为它是出 ...

  8. MOOC(5)- mock模拟返回响应数据

    1.安装mock 1)pip install mock 2)或者下载离线安装包 2.mock散装使用 import unittest from mock import mock from day_20 ...

  9. Linux下Centos 7如何关闭防火墙?

    Linux下的防火墙有两种:Iptables和Firewall(概念以及区别大家可以自行搜索).为什么要关闭防火墙呢?主要是我们都过Linux搭建服务器的时候其他机器访问会被墙掉,例如:Tomcat, ...

  10. hadoop报错:could only be replicated to 0 nodes, instead of 1

    错误 [root@hadoop test]# hadoop jar hadoop.jarcom.hadoop.hdfs.CopyToHDFS 14/01/26 10:20:00 WARN hdfs.D ...