私もプロジェクトを作っているときにこのボタンを発見し、たくさんのデモを見つけて少しずつ試してみたところ、このボタンも非常にクールであることがわかりました。
いくつかの属性 (@keyframes、::after、::before) が使用されます。
それらが何のためにあるのか調べてみましょう
@キーフレーム
キーフレーム @keyframes
アット ルール ルールは、アニメーション シーケンス内のキーフレーム (またはウェイポイント) のスタイルを定義することによって、CSS アニメーション シーケンスの中間ステップを制御します。トランジションとは対照的に、キーフレームはアニメーション シーケンスの中間ステップを制御できます。
キーフレームの使用方法:
キーフレームを使用するには、まず名前付き @keyframes
ルールを作成します。その後、animation-name プロパティを使用してアニメーションをキーフレーム宣言に一致させることができます。各 @keyframes
ルールには複数のキーフレーム、つまりスタイル ブロック ステートメントが含まれています。各キーフレームには名前としてパーセンテージ値が含まれており、この値は、このフレームに含まれるスタイルがアニメーション中にどの段階でトリガーされるかを表します。
::後
CSS 擬似要素は、::after
選択した要素の最後の子として擬似要素を作成するために使用されます。通常、content 属性は要素に装飾的なコンテンツを追加するために使用されます。この仮想要素は、デフォルトではインライン要素です。
彼の文法形式:
element:after { style properties } /* CSS2 语法 */
element::after { style properties } /* CSS3 语法 */
::after
表記はCSS 3 中引入的,
:::符号是用来区分[伪类](/zh-CN/CSS/Pseudo-classes)和伪元素的。支持 CSS3 的浏览器同时也都支持 CSS2 中引入的表示法
after`内にあります。
::前
CSS では、::before は、生成されたコンテンツ要素を表す疑似クラス要素であり、対応する要素の抽象化可能なスタイルの最初の子要素、つまり、選択された要素の最初の子要素を表します。
::before を使用すると、挿入するコンテンツを要素の他のコンテンツの前に挿入し、デフォルトでインラインで表示します。::before では、 content 属性を使用してコンテンツの値を指定する必要があります。
例: リンクの前にスターを追加するなど。
a::before{
content:"★"
}
さて、まずはこれをやってみましょう。今日のテーマを見てみましょう。
ボタンは次の効果を実現します。
全体的なコードは次のとおりです。
ボタンのスタイルは少しやりすぎですが、使用する際はメソッドにカプセル化することも、別のCSSページにカプセル化することもできますので、使用する際は使用するページのスタイルを参照するだけで大丈夫です。
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>css——button</title>
<style>
.dialog_but {
display: flex;
justify-content: center;
align-items: center;
width: 13rem;
height: 3rem;
background-size: 300% 300%;
backdrop-filter: blur(1rem);
border-radius: 5rem;
transition: 0.5s;
animation: gradient_301 5s ease infinite;
border: double 4px transparent;
background-image: linear-gradient(#212121, #212121), linear-gradient(137.48deg, #ffdb3b 10%,#FE53BB 45%, #8F51EA 67%, #0044ff 87%);
background-origin: border-box;
background-clip: content-box, border-box;
}
#dialog_container {
position: fixed;
z-index: -1;
width: 100%;
height: 100%;
overflow: hidden;
transition: 0.5s;
backdrop-filter: blur(1rem);
border-radius: 5rem;
}
strong {
z-index: 2;
font-family: 'Avalors Personal Use';
font-size: 12px;
letter-spacing: 5px;
color: #FFFFFF;
text-shadow: 0 0 4px white;
}
#dialog_glow {
position: absolute;
display: flex;
width: 12rem;
}
.dialog_circle {
width: 100%;
height: 30px;
filter: blur(2rem);
animation: pulse_3011 4s infinite;
z-index: -1;
}
.dialog_circle:nth-of-type(1) {
background: rgba(254, 83, 186, 0.636);
}
.dialog_circle:nth-of-type(2) {
background: rgba(142, 81, 234, 0.704);
}
.dialog_but:hover #dialog_container {
z-index: 1;
background-color: #212121;
}
.dialog_but:hover {
transform: scale(1.1)
}
.dialog_but:active {
border: double 4px #FE53BB;
background-origin: border-box;
background-clip: content-box, border-box;
animation: none;
}
.dialog_but:active .dialog_circle {
background: #FE53BB;
}
#dialog_content_container {
position: relative;
background: transparent;
width: 200rem;
height: 200rem;
}
#dialog_content_container::after {
content: "";
position: absolute;
top: -10rem;
left: -100rem;
width: 100%;
height: 100%;
animation: animStarRotate 90s linear infinite;
}
#dialog_content_container::after {
background-image: radial-gradient(#ffffff 1px, transparent 1%);
background-size: 50px 50px;
}
#dialog_content_container::before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 170%;
height: 500%;
animation: animStar 60s linear infinite;
}
#dialog_content_container::before {
background-image: radial-gradient(#ffffff 1px, transparent 1%);
background-size: 50px 50px;
opacity: 0.5;
}
/*控制按钮中 小点点的移动*/
@keyframes animStar {
from {
transform: translateY(0);
}
to {
transform: translateY(-135rem);
}
}
/*控制按钮中 小点点的旋转*/
@keyframes animStarRotate {
from {
transform: rotate(360deg);
}
to {
transform: rotate(0);
}
}
@keyframes gradient_301 {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
@keyframes pulse_3011 {
0% {
transform: scale(0.75);
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(0, 0, 0, 0);
}
100% {
transform: scale(0.75);
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}
</style>
</head>
<body>
<button type="button" class="dialog_but">
<strong>按钮</strong>
<div id="dialog_container">
<div id="dialog_content_container"></div>
</div>
<div id="dialog_glow">
<div class="dialog_circle"></div>
<div class="dialog_circle"></div>
</div>
</button>
</body>
</html>