原文地址:https://segmentfault.com/a/1190000014734039

感想:伪元素::before ::after 真的很强大,动画也是。

HTML代码:

<div class="coffee">
<div class="vapor">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="cup"></div>
<div class="plate"></div>
</div>

CSS代码:

html, body {
margin:;
padding:;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: brown;
}
.coffee {
display: flex;
flex-direction: column;
align-items: center;
height: calc(9em + 1em +2em);
position: relative;
} /* 画出杯子主体 */
.coffee .cup{
position: relative;
width: 10em;
height: 9em;
background-color: white;
border-bottom-left-radius: 1.5em;
border-bottom-right-radius: 1.5em;
}
/* 用伪元素画出杯口 */
.coffee .cup::before{
content: '';
position: absolute;
width: 100%;
height: 2em;
background-color: chocolate;
border: 0.5em solid white;
box-sizing: border-box;
border-radius: 50%;
top: -1em;
box-shadow: inset 0 0 1em rgba(0,0,0,0.5);
}
/* 用伪元素画出杯子把手 */
.coffee .cup::after{
content:'';
position: absolute;
width: 3em;
height: 3.5em;
border: 0.8em solid white;
border-radius: 50%;
top: 20%;
left: 80%;
}
/* 画出托盘 */
.coffee .plate {
width: 16em;
height: 1em;
background-color: white;
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
position: absolute;
bottom: -1px;
}
/* dom元素增加杯中冒出的热气 */
/* 冒出的热气 */
.coffee .vapor{
width: 7em;
display: flex;
justify-content: space-between;
}
.coffee .vapor span{
width: 0.1em;
min-width: 1px;
height: 2em;
background-color: white;
animation: evaporation 2s linear infinite;
filter: opacity(0);
}
@keyframes evaporation{
from{
transform: translateY(0);
filter: opacity(1) blur(0.2em);
}
to{
transform: translateY(-4em);
filter: opacity(0) blur(0.4em);
}
}
/* 最后,调整每条热气的延迟时间,使动感更强 */
.coffee .vapor span:nth-child(1) {
animation-delay: 0.5s;
}
.coffee .vapor span:nth-child(2) {
animation-delay: 0.1s;
}
.coffee .vapor span:nth-child(3) {
animation-delay: 0.3s;
}
.coffee .vapor span:nth-child(4) {
animation-delay: 0.4s;
}
.coffee .vapor span:nth-child(5) {
animation-delay: 0.2s;
}

最新文章

  1. iOS支付宝支付总结
  2. WPF Tranform-Flip Image
  3. C#的变迁史 - C# 1.0篇
  4. for_each()的返回值
  5. 关于 IOS 发布的点点滴滴记录(一)
  6. docker 错误
  7. C++中虚函数功能的实现机制
  8. Vue 国际化 vue-i18n 用法详解
  9. JAVA 中的 反射
  10. Windows下免安装版mysql5.7的初始密码
  11. Linux新加磁盘挂载和重启自动挂载
  12. postma概念与使用
  13. Django 中文和时区设置
  14. CentOS 7安装Redis
  15. 【Linux】ps命令
  16. linux学习思维导图(转)
  17. DOM系列基础知识
  18. Qt Creator + MinGW 在windows 下的调试GDB停止工作解决
  19. 20155313 杨瀚 《网络对抗技术》实验五 MSF基础应用
  20. 021.14 IO流 管道流

热门文章

  1. RichEdit文字背景色的处理
  2. webservice的model层命名空间不同的问题
  3. Laravel 输出最后一条sql
  4. win10和ubuntu16.04双系统Geom Error
  5. centos7 安装 codeblock(rpm)
  6. [Easyui - Grid]为easyui的datagrid、treegrid增加表头菜单,用于显示或隐藏列
  7. 配置文件elasticsearch.yml详解
  8. OpenStack存储(单节点)
  9. android 照片旋转并保存
  10. jmx - first demo