我正在尝试创建一个加载DIV
,其边框看起来像一个不确定的进度环微调器。
根据https://css-tricks.com/gradient-borders-in-css/上的示例之一,我非常接近
当边框不旋转时,这很棒。当您border
在:before
元素中设置 以匹配元素中的透明border
时,gradient-box
静态渐变边框看起来很完美。
但是,一旦添加了动画,因为整个:before
元素会旋转,您会得到一个非常奇怪的效果 - 如下例所示。
.gradient-box {
display: flex;
align-items: center;
width: 90%;
margin: auto;
max-width: 22em;
position: relative;
padding: 30% 2em;
box-sizing: border-box;
border: 5px solid blue;
color: #FFF;
background: #000;
background-clip: padding-box; /* !importanté */
border: solid 5px transparent; /* !importanté */
border-radius: 1em;
}
.gradient-box:before {
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -1;
margin: -35px; /* !importanté */
border-radius: inherit; /* !importanté */
background: conic-gradient(#0000ff00, #ff0000ff);
-webkit-animation: rotate-border 5s linear infinite;
-moz-animation: rotate-border 5s linear infinite;
-o-animation: rotate-border 5s linear infinite;
animation: rotate-border 3s linear infinite;
}
@keyframes rotate-border {
to {
transform: rotate(360deg);
}
}
html { height: 100%; background: #000; display: flex; }
body { margin: auto; }
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Loading DIV Test</title>
</head>
<body>
<div id="loadingBox" class="gradient-box">
<p>Loading.</p>
</div>
</body>
我试过玩溢出:隐藏;但是边框只是消失了..有什么方法可以“屏蔽” :before 元素,以使该加载 Div 后面的任何内容在其后面仍然可见,从而使边框保持其预期宽度?
基本上,我的目标是旋转中的颜色渐变border
以产生旋转/旋转边缘的效果。