本篇文章给大家带来的内容是关于如何使用纯CSS实现一张纪念卓别林的卡片(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
效果预览
源代码下载
https://github.com/comehope/front-end-daily-challenges
代码解读
定义 dom,容器中包含的 3 个元素分别代表帽子、胡须和手杖:
<figure class="chaplin"> <span class="hat"></span> <span class="beard"></span> <span class="stick"></span> </figure>
居中显示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; }
定义容器尺寸,并设置子元素水平居中:
.chaplin { width: 40em; height: 30em; font-size: 10px; background-color: #eee; box-shadow: 0 0 3em rgba(0, 0, 0, 0.2); display: flex; flex-direction: column; align-items: center; }
定义默认颜色,后面用 currentColor
引用此颜色:
.chaplin { color: #555; }
画出帽子的轮廓:
.chaplin { position: relative; } .hat { position: absolute; width: 6.4em; height: 4.6em; background-color: currentColor; border-radius: 2.3em 2.3em 0 0; top: 1.4em; }
用伪元素画出帽沿:
.hat::before { content: ''; position: absolute; width: 10em; height: 0.8em; background-color: currentColor; border-radius: 0.4em; top: calc(100% + 0.4em); left: calc((100% - 10em) / 2); }
画出胡子:
.beard { position: absolute; width: 1.5em; height: 0; top: 11.6em; border: solid transparent; border-width: 0 0.4em 1em 0.4em; border-bottom-color: currentColor; }
画出手杖的杖杆:
.stick { position: absolute; width: 0.8em; height: 10.5em; background-color: currentColor; bottom: 0; }
用 ::before
伪元素画出手杖的握柄:
.stick::before { content: ''; position: absolute; box-sizing: border-box; width: 5.6em; height: 3em; border: 0.8em solid; border-radius: 5.6em 5.6em 0 0; border-bottom: none; top: -3em; }
用 ::after
伪元素修饰握柄的端点,使其圆润自然:
.stick::after { content: ''; position: absolute; width: 0.8em; height: 0.8em; background-color: currentColor; border-radius: 50%; left: calc(5.6em - 0.8em); top: -0.4em; }
使手杖水平居中:
.stick { left: calc((100% - (5.6em - 0.8em)) / 2); }
至此,抽象的卓别林形象完成,接下来排版一句他的名言。
在 dom 中增加一个 .quote
元素,并把一句话分为 3 段:
<figure class="chaplin"> <span class="hat"></span> <span class="beard"></span> <span class="stick"></span> <p class="quote"> <span>a day without</span> <span>laughter</span> <span>is a day wasted</span> </p> </figure>
定位文字,并竖排 3 段文字:
.quote { position: absolute; left: 50%; bottom: 2.5em; font-family: sans-serif; text-transform: uppercase; font-weight: bold; display: flex; flex-direction: column; }
调整字号和字间距,使 3 段文字对齐:
.quote span:nth-child(1) { letter-spacing: 0.05em; } .quote span:nth-child(2) { font-size: 1.6em; }
大功告成!
以上是如何使用纯CSS实现一张纪念卓别林的卡片(附源码)的详细内容。更多信息请关注PHP中文网其他相关文章!

具有CSS的自定义光标很棒,但是我们可以将JavaScript提升到一个新的水平。使用JavaScript,我们可以在光标状态之间过渡,将动态文本放置在光标中,应用复杂的动画并应用过滤器。

互动CSS动画和元素相互启动的元素在2025年似乎更合理。虽然不需要在CSS中实施乒乓球,但CSS的灵活性和力量的增加,可以怀疑Lee&Aver Lee&Aver Lee有一天将是一场

有关利用CSS背景滤波器属性来样式用户界面的提示和技巧。您将学习如何在多个元素之间进行背景过滤器,并将它们与其他CSS图形效果集成在一起以创建精心设计的设计。

好吧,事实证明,SVG的内置动画功能从未按计划进行弃用。当然,CSS和JavaScript具有承载负载的能力,但是很高兴知道Smil并没有像以前那样死在水中

是的,让#039;跳上文字包装:Safari Technology Preview In Pretty Landing!但是请注意,它与在铬浏览器中的工作方式不同。

此CSS-tricks更新了,重点介绍了年鉴,最近的播客出现,新的CSS计数器指南以及增加了几位新作者,这些新作者贡献了有价值的内容。

在大多数情况下,人们展示了@Apply的@Apply功能,其中包括Tailwind的单个property实用程序之一(会改变单个CSS声明)。当以这种方式展示时,@Apply听起来似乎很有希望。如此明显


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

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

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

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