/* CSS 边框发光效果 */
/* 1. 使用 box-shadow 实现边框发光效果 */
.box-shadow-glow {
width: 200px;
height: 200px;
background-color: #3498db;
margin: 50px auto;
box-shadow: 0 0 20px rgba(52, 152, 219, 0.8); /* 发光效果 */
}
/* 2. 使用 outline 和 filter 实现更柔和的发光效果 */
.outline-glow {
width: 200px;
height: 200px;
background-color: #e74c3c;
margin: 50px auto;
outline: 10px solid #ff7b69;
filter: blur(10px); /* 模糊效果使发光更柔和 */
}
/* 3. 使用 ::before 和 ::after 伪元素实现动态发光效果 */
.dynamic-glow {
position: relative;
width: 200px;
height: 200px;
background-color: #2ecc71;
margin: 50px auto;
border-radius: 10px;
overflow: hidden;
}
.dynamic-glow::before,
.dynamic-glow::after {
content: '';
position: absolute;
top: -10px;
left: -10px;
right: -10px;
bottom: -10px;
background: radial-gradient(circle at center, rgba(46, 204, 113, 0.8), transparent);
z-index: -1;
animation: glow 2s infinite alternate;
}
@keyframes glow {
from {
transform: scale(1);
opacity: 0.5;
}
to {
transform: scale(1.2);
opacity: 0.1;
}
}
使用 box-shadow
实现边框发光效果:
box-shadow
属性用于给元素添加阴影效果。通过设置较大的模糊半径(如 20px
),可以让阴影看起来像发光效果。rgba(52, 152, 219, 0.8)
是发光的颜色和透明度。使用 outline
和 filter
实现更柔和的发光效果:
outline
属性用于在元素外部绘制一条线,通常不会影响布局。filter: blur(10px)
使这条线变得模糊,从而产生柔和的发光效果。使用 ::before
和 ::after
伪元素实现动态发光效果:
::before
和 ::after
伪元素创建一个渐变背景,并使用 animation
实现动态缩放效果,模拟出脉动的发光效果。@keyframes glow
定义了发光的动画,从较小到较大,再从较大到较小,形成循环的发光效果。上一篇:css 加下划线
下一篇:css flex 布局
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站