效果预览

在线演示

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

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

可交互视频教程

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

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

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

源代码下载

在线下载

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

https://github.com/comehope/front-end-daily-challenges

代码解读

定义 dom,容器中包含文本:

<div class="warning">ERROR 404</div>

居中显示:

body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: rgb(20%, 20%, 20%);
}

定义文字样式:

.warning {
color: whitesmoke;
font-size: 100px;
font-family: sans-serif;
font-weight: bold;
}

用伪元素定义边框尺寸:

.warning {
position: relative;
padding: 0.6em 0.4em;
} .warning::before,
.warning::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0.2em solid;
box-sizing: border-box;
}

把边框分为两部分,拼在一起:

.warning::before,
.warning::after {
border: 0.2em solid transparent;
color: orangered;
} .warning::before {
border-top-color: currentColor;
border-right-color: currentColor;
} .warning::after {
border-bottom-color: currentColor;
border-left-color: currentColor;
}

把上边框和右边框下沉一层:

.warning::before {
z-index: -1;
}

为下边框和在边框加上阴影:

.warning::after {
box-shadow: 0.3em 0.3em 0.3em rgba(20%, 20%, 20%, 0.8);
}

最后,让边框转起来:

.warning::before,
.warning::after {
animation: rotating 10s infinite;
} @keyframes rotating {
to {
transform: rotate(360deg);
}
}

大功告成!

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

最新文章

  1. Centos7中所有的关机命令的奇怪现象
  2. Maven基础知识(转)
  3. CodeForces#275--DIV 2--A
  4. maven No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
  5. easyui-datebox 和easyui-datetimebox 设置默认时间当前时间
  6. cf div2 238 c
  7. Matlab---size,length和numel函数的用法
  8. bzoj4578: [Usaco2016 OPen]Splitting the Field
  9. JavaCodeTra 猴子选猴王 约瑟夫循环
  10. PHP 网页爬虫
  11. 为何某些公司不允许使用C++ STL?
  12. 公共 DNS server IP 地址
  13. LightOj 1148 Basic Math
  14. 使用基于Android网络通信的OkHttp库实现Get和Post方式简单操作服务器JSON格式数据
  15. OpenResty 自定义 access_log 格式
  16. vue js实现获取两个日期之间所有日期
  17. Windows抓屏技术
  18. 设置JAVA环境变量
  19. mongodb三种引擎测试(转)
  20. 【Devops】【docker】【CI/CD】jenkins 清除工作空间报错Error: Wipe Out Workspace blocked by SCM

热门文章

  1. A - Beautiful numbers
  2. Sql Server的两个小技巧
  3. find搜索文件系统,实时搜索
  4. 关于IE兼容的问题
  5. Web开发入门不得不看章
  6. Android 6.0 运行时权限处理完全解析 (摘抄)
  7. 如何使用KeyChain保存和获取UDID
  8. vijos 1034 家族(水题日常)
  9. 洛谷 P1330 封锁阳光大学
  10. mysql Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona