本篇文章给大家带来的内容是关于如何使用纯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中文网其他相关文章!

选择Flexbox还是Grid取决于布局需求:1)Flexbox适用于一维布局,如导航栏;2)Grid适合二维布局,如杂志式布局。两者在项目中可结合使用,提升布局效果。

包含CSS文件的最佳方法是使用标签在HTML的部分引入外部CSS文件。1.使用标签引入外部CSS文件,如。2.对于小型调整,可以使用内联CSS,但应谨慎使用。3.大型项目可使用CSS预处理器如Sass或Less,通过@import导入其他CSS文件。4.为了性能,应合并CSS文件并使用CDN,同时使用工具如CSSNano进行压缩。

是的,youshouldlearnbothflexboxandgrid.1)flexboxisidealforone-demensional,flexiblelayoutslikenavigationmenus.2)gridexcelstcelsintwo-dimensional,confffferDesignssignssuchasmagagazineLayouts.3)blosebothenHancesSunHanceSlineHancesLayOutflexibilitibilitibilitibilitibilityAnderibilitibilityAndresponScormentilial anderingStruction

重构自己的代码看起来是什么样的?约翰·瑞亚(John Rhea)挑选了他写的一个旧的CSS动画,并介绍了优化它的思维过程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingmatematingmultationmatingMultationPropertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用BombingingWithjavofofofofofoffo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他们可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑战挑战InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)创造性

使用滚动阴影,尤其是对于移动设备,是克里斯以前涵盖的一个微妙的UX。杰夫(Geoff)涵盖了一种使用动画限制属性的新方法。这是另一种方式。


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver Mac版
视觉化网页开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

WebStorm Mac版
好用的JavaScript开发工具