css实现多种边框及多边形发光效果练习

一、圆角阴影(文字标题时用到)
在这里插入图片描述

.shadow {
    width: 200px;
    height: 40px;
    border-radius: 20px;
    background-color: #ffa500;
    box-shadow: 0 5px 0 0 #ff4500;
  }

二、边框四角特殊效果
在这里插入图片描述
方法一:利用伪元素:before,:after

/*less样式*/
.corners {
    position: relative;
    width: 200px;
    height: 200px;
    border: 2px solid #ffa500;
    &:before{
      content: '';
      position: absolute;
      bottom: -1px;
      top: -1px;
      left: 20px;
      right: 20px;
      border-bottom: 1px solid #fff;
      border-top: 1px solid #fff;
    }
    &:after{
      content: '';
      position: absolute;
      left: -1px;
      right: -1px;
      top: 20px;
      bottom:20px;
      border-left: 1px solid #fff;
      border-right: 1px solid #fff;
    }
  }

如果要在div里写文字,添加适当的padding,:before、:after中的border-color改成对应的背景色;通过改变left、right、top、bottom以及border-width可以分别实现以下效果:
AltAlt
方法二:利用线性渐变以及背景定位
在这里插入图片描述

.border {
    width: 200px;
    height: 200px;
    border: 1px solid #ffa500;
    background: linear-gradient(#ffa500, #ffa500) left top,
    linear-gradient(#ffa500, #ffa500) left top,
    linear-gradient(#ffa500, #ffa500) right top,
    linear-gradient(#ffa500, #ffa500) right top,
    linear-gradient(#ffa500, #ffa500) left bottom,
    linear-gradient(#ffa500, #ffa500) left bottom,
    linear-gradient(#ffa500, #ffa500) right bottom,
    linear-gradient(#ffa500, #ffa500) right bottom;
    background-repeat: no-repeat;
    background-size: 1px 20px, 20px 1px;
  }

知识点:
1、linear-gradient() 函数用于创建一个线性渐变的 “图像”
linear-gradient(angle, color-stop1, color-stop2, …):
取值如下:
angle:用角度值制定渐变的方向或顺时针角度
to left:从右到左,相当于:270deg
to right:从右到左,相当于:90deg
to top:从右到左,相当于:0deg
to bottom:从右到左,相当于:180deg,这是默认值,可不写
color-stop:用于制定渐变的起止颜色
color:指定颜色
length:用长度值制定起止色位置,不允许负值
percentage:用百分比制定起止位置
background-image: linear-gradient(135deg,#fff 30%, #0ae 31%,#0ae 66%, #fff 80%)
background-image: linear-gradient(顺时针角度, 开始颜色 结束位置, 中间颜色1 开始位置,中间颜色1 结束位置,结束颜色 开始位置)
如果数字不是连续的,他们之间存在数值差,那么数值差的之间的两种颜色默认就是渐变效果。如果最后一个颜色没有规定位置,那么渐变结束位置就是100%。
2、background:设置多个背景图像(并指定他们的位置)
background:bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
background 的简写属性不是按照规定的顺序来书写的,可以根据自己的喜好自定义属性的书写顺序。
background-position:设置背景图像的起始位置。
取值:
在这里插入图片描述
background-size:设置背景图片大小;
      background-size: 1px 20px;第一个值指定图片的宽度,第二个值指定图片的高度;
      background-size: 1px 20px, 20px 1px;逗号分隔的多个值:设置多重背景;
3、多背景写法
多个背景图片用逗号隔开,每个背景图片都是以层的形式显示,越靠前的图片层级越高。
每一个背景图片的写法都和以前单个背景图片的写法是一样的。可以指定图片的平铺方式,位置等等。
background-size个数如果比background少,那么重复background-size的设置。
其他效果展示:
1、四角颜色不一样
在这里插入图片描述

.border{
    width: 200px;
    height: 200px;
    background: linear-gradient(#07c160, #07c160) left top,
    linear-gradient(#07c160, #07c160) left top,
    linear-gradient(#1989fa, #1989fa) right top,
    linear-gradient(#1989fa, #1989fa) right top,
    linear-gradient(#ee0a24, #ee0a24) left bottom,
    linear-gradient(#ee0a24, #ee0a24) left bottom,
    linear-gradient(#ff8917, #ff8917) right bottom,
    linear-gradient(#ff8917, #ff8917) right bottom;
    background-repeat: no-repeat;
    background-size: 2px 20px, 20px 2px;
  }

2、切角效果
在这里插入图片描述

.cut {
   width: 200px;
   height: 200px;
   background: linear-gradient(135deg, transparent 15px, #F8E2EB 0) top left,
   linear-gradient(-135deg, transparent 15px, #ace 0) top right,
   linear-gradient(-45deg, transparent 15px, #F8E2EB 0) bottom right,
   linear-gradient(45deg, transparent 15px, #ace 0) bottom left;
   background-size: 50% 50%; /*每个块在水平和垂直方向上都占元素尺寸的50%*/
   background-repeat: no-repeat;
}

3、内圆角效果
在这里插入图片描述

.round {
   width: 200px;
   height: 200px;
   background: radial-gradient(circle at top left, transparent 15px, #F8E2EB 0) top left,
   radial-gradient(circle at top right, transparent 15px, #ace 0) top right,
   radial-gradient(circle at bottom right, transparent 15px, #F8E2EB 0) bottom right,
   radial-gradient(circle at bottom left, transparent 15px, #ace 0) bottom left;
   background-size: 50% 50%;
   background-repeat: no-repeat;
}

3、四角是小方块
在这里插入图片描述

.s-corner {
   width: 200px;
   height: 200px;
   box-shadow: 0px 0px 10px #00bfff;
   background: linear-gradient(#00bfff,#00bfff) left top,
   linear-gradient(#00bfff,#00bfff) left bottom,
   linear-gradient(#00bfff,#00bfff) right top,
   linear-gradient(#00bfff,#00bfff) right bottom;
   background-size: 4px 4px;
   background-repeat: no-repeat;
}

三、多重边框效果
通过box-shadow可实现多重边框效果。
在这里插入图片描述
1、box-shadow

.box{
   width: 200px;
   height: 200px;
   box-shadow: 0px 0px 0px 5px #ee0a24, 0px 0px 0px 10px #07c160;
}

2、outline

.box{
   width: 200px;
   height: 200px;
   border: 5px solid #ee0a24;
   outline: 5px solid #07c160;
}

此种方式还可设置为虚线等样式,兼容性好,不过只能实现双层边框,而且outline没有圆角效果。
四、内发光效果
在这里插入图片描述

.light {
   width: 200px;
   height: 200px;
   box-shadow: 0px 0px 10px #ee0a24 inset, 0px 0px 0px 15px #fff inset, 0px 0px 10px 15px #07c160 inset;
}

五、斜六边形发光效果
在这里插入图片描述

.six {
   width: 200px;
   height: 70px;
   position: relative;
   border-radius: 1px;
   filter: drop-shadow(0 0 6px #07c160);/*滤镜投影,实现阴影效果*/
   background: #00bfff;
}
.six:before {
   content: '';
   position: absolute;
   width: 30px;
   height: 63px;
   border-radius: 2px;
   transform-origin: top right; /*旋转原点*/
   transform: rotate(-25deg);
   left: -30px; /*跟宽度一致*/
   top: 0;
   background: #00bfff;
}
.six:after {
   content: '';
   position: absolute;
   width: 30px;
   height: 63px;
   border-radius: 2px;
   transform-origin: left bottom;
   transform: rotate(-25deg);
   right: -30px;
   bottom: 0;
   background: #00bfff;
}

如果要添加文字,需要在内部添加div或者span,设置position:relative;z-index:10;
因为这个形状不是标准的,所以伪元素的宽、高、旋转角度得重新计算,无法直接套用。

  • 9
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实现CSS边框发光动画效果,您可以使用CSS的animation属性和box-shadow属性。首先,您可以为具有边框的元素创建一个CSS类,例如名为"glow-border"的类。然后,您可以在该类中定义动画和光晕效果。 下面是一个示例代码: ```css .glow-border { animation: glow 2s infinite; border: 2px solid transparent; } @keyframes glow { 0% { box-shadow: 0 0 5px #00ff00; } 50% { box-shadow: 0 0 20px #00ff00; } 100% { box-shadow: 0 0 5px #00ff00; } } ``` 在上面的代码中,我们创建了一个名为"glow-border"的类,并为其指定了一个名为"glow"的动画。该动画会在2秒内循环播放。我们还使用了border属性来设置元素的边框样式。 在关键帧动画中,我们定义了三个关键帧,分别是0%、50%和100%。在0%和100%的关键帧中,我们使用box-shadow属性为元素添加一个绿色的发光效果。在50%的关键帧中,我们将box-shadow的大小增加,以增强发光效果。 您可以将"glow-border"类应用于您想要添加发光动画效果的元素上,例如一个div元素。通过这样做,您将看到边框发光的动画效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [【前端实例代码】使用 HTML CSS 和 JavaScript 实现具有带边框悬停动画的彩色发光霓虹灯悬停效果的动画按钮...](https://blog.csdn.net/qq_22182989/article/details/126413773)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值