CSSを使用して境界線の動的グラデーションカラー効果を実現します。少しでもお役に立てれば幸いです。
ボーダー.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" />
<title>边框</title>
<link rel="stylesheet" href="css/动态边框.css">
</head>
<body>
<div>鼠标移入此处,边框变色</div>
</body>
</html>
ダイナミックボーダー.css
/* 初始状态,注意设置相对定位 */
div {
width: 300px;
height: 100px;
line-height: 100px;
text-align: center;
box-sizing: border-box;
position: relative;
}
/* 渐变色边框 */
div::before {
content: "";
position: absolute;
left: 0;
top: 0;
border-top: 1px solid;
border-left: 1px solid;
border-image: linear-gradient(to bottom, #eda901, #d16cc7) 1 10;
width: 0;
height: 0;
transition: all 0.4s ease-out 0s;
visibility: hidden;
box-sizing: border-box;
}
div::after {
content: "";
position: absolute;
right: 0;
bottom: 0;
border-right: 1px solid;
border-bottom: 1px solid;
border-image: linear-gradient(to bottom, #eda901, #d16cc7) 1 10;
width: 0;
height: 0;
transition: all 0.4s ease-out 0s;
visibility: hidden;
box-sizing: border-box;
}
div:hover::before {
width: 100%;
height: 100%;
visibility: visible;
}
div:hover::after {
width: 100%;
height: 100%;
visibility: visible;
}
実際には、元の div に別のレイヤーを追加することで、境界線の動的な効果が得られます。元の div 内にクリックしたいボタンがある場合は、相対的な配置位置を追加できます。 z-index プロパティが少し高くなります。
本来の見た目はこんな感じです。
マウスオーバー後の表示は次のようになります。
真ん中に徐々に効果を出していくフレームもありますが、GIFを作っていないのでそれで間に合わせましょう。