有没有一种方法可以编程一个看起来像RGB灯带的变色边框



我目前正准备帮助一位家庭成员为他们的业务开发一个网站。对于网站的游戏部分,我希望在标题的底部有一个边框,可以渐变RGB颜色,就像你安装在墙上的RGB条一样。我对编程和开发仍然很熟悉,所以有什么方法可以在本机或包中实现这一点吗?我知道它可能需要JavaScript,但有没有一种方法可以用CSS原生地做到这一点?谢谢

灵感示例:https://youtu.be/Pxt9sGTsvFk?t=184

你好,如果你想移动或更改rbg边框颜色,你可以使用下面的代码,我希望你能发现这个答案对有用

HTML


<div class="block moving-glow"></div>

CSS


.block {
position: relative;
margin: 10% auto 0;
width: 50%;
height: 400px;
background: linear-gradient(0deg, #000, #272727);
}
.moving-glow:before, .moving-glow:after {
content: '';
position: absolute;
left: -2px;
top: -2px;
background: linear-gradient(45deg, #fb0094, #0000ff, #00ff00,#ffff00, #ff0000, #fb0094, 
#0000ff, #00ff00,#ffff00, #ff0000);
background-size: 400%;
width: calc(100% + 10px);
height: calc(100% + 10px);
z-index: -1;
animation: anim-moving-glow 20s linear infinite;

}
@keyframes anim-moving-glow {
0% {
background-position: 0 0;
}
50% {
background-position: 400% 0;
}
100% {
background-position: 0 0;
}
}
.moving-glow:after {
filter: blur(30px);
}

有人给我寄来了我需要的东西!感谢伦敦政治经济学院!

https://codepen.io/bramus/pen/rNWByYz

HTML:

<footer>
<p>Demo 4/4 for <a href="https://brm.us/animated-gradient-border" target="_top">https://brm.us/animated-gradient-border</a></p>
<p>Don't see an animation? That's because your browser does not support <code>@property</code>.<br />Check out <a href="https://codepen.io/bramus/pen/XWMwPgO" target="_top">this forked version</a> which includes a fallback for your browser.</p>
</footer>

CSS:

div {
--angle: 0deg;
width: 50vmin;
height: 50vmin;
border: 10vmin solid;
border-image: conic-gradient(from var(--angle), red, yellow, lime, aqua, blue, magenta, red) 1;
animation: 10s rotate linear infinite;
}
@keyframes rotate {
to {
--angle: 360deg;
}
}
@property --angle {
syntax: '<angle>';
initial-value: 0deg;
inherits: false;
}
input[type="checkbox"] {
position: fixed;
top: 1em;
left: 1em;
}
input[type="checkbox"]:after {
content: 'Toggle Fill';
white-space: nowrap;
padding-left: 1.5em;
}
input[type="checkbox"]:checked + div {
border-image-slice: 1 fill;
}
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
display: grid;
place-items: center;
background: #fff;
}
footer {
text-align: center;
font-style: italic;
}

这就是如何创建rgb,将颜色边框更改为html页面的侧边框。

HTML代码:-

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Document</title>
</head>
<body>
<div id="progressbar"></div>
<div id="progressbar1"></div>
</body>
</html>

CSS代码:-

*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
background-color:black;
}
#progressbar
{
position: fixed;
top: 0;
right: 0;
width: 10px;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
animation: animate 5s linear infinite;
}
@keyframes animate
{
0%,100%
{
filter: hue-rotate(0deg);
}
100%
{
filter: hue-rotate(360deg);
}
}
#progressbar:before
{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
filter: blur(30px);
}
#progressbar:after
{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
filter: blur(30px);
}
#progressbar1
{
position: fixed;
top: 0;
left: 0;
width: 10px;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
animation: animate 5s linear infinite;
}
@keyframes animate
{
0%,100%
{
filter: hue-rotate(0deg);
}
100%
{
filter: hue-rotate(360deg);
}
}
#progressbar1:before
{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
filter: blur(30px);
}
#progressbar1:after
{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to top, #008aff,#00ffe7);
filter: blur(30px);
}