html文字距离边框距离视频,前端每日实战:34# 视频演示如何用纯 CSS 创作在文本前后穿梭的边框...

bVbbyr9?w=500&h=500

效果预览

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

可交互视频教程

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

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

源代码下载

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

代码解读

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

ERROR 404

居中显示:

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);

}

}

大功告成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值