如何使阴影淡入(用于HTML的CSS样式表)

huangapple go评论50阅读模式
英文:

How to make the shadow fade in (css stylesheet for html)

问题

我想要当有人悬停在按钮上时,有些光晕淡入。我尝试了这段代码:
 .discord_join_button:hover{
    color: rgba(255, 255, 255, 1);
    box-shadow: 0 0px 60px #2332d8;
    animation-duration: 500ms;
}
不知何故,这并不起作用,阴影突然出现

我原本期望它会淡入,而不仅仅出现
英文:

I want to make it so when somebody hovers over a button, some glow fades in. I tried that with this code:

     .discord_join_button:hover{
        color: rgba(255, 255, 255, 1);
        box-shadow: 0 0px 60px #2332d8;
        animation-duration: 500ms;
    }

for some reason this isn't working and the box-shadow just pops into existence

I was expecting it to fade, not just show up

答案1

得分: 0

.discord_join_button{
    color: rgba(255, 255, 255, 1);
    box-shadow: 0 0px 60px rgba(0,0,0,0);
    transition: 500ms;
}

.discord_join_button:hover{
    box-shadow: 0 0px 60px rgba(0,0,0,1);
}
英文:
     .discord_join_button{
        color: rgba(255, 255, 255, 1);
        box-shadow: 0 0px 60px rgba(0,0,0,0);
        transition: 500ms;
    }

     .discord_join_button:hover{
        box-shadow: 0 0px 60px rgba(0,0,0,1);
    }

Use rgba.
And transition should be applied before hover.

I don't know if it's what you want, but if you write the box-shadow value in reverse, it's also possible to make it work in reverse.

答案2

得分: 0

你可以通过将transition属性指定给button基本样式来实现“淡入”效果。例如:

.discord_join_button {
    color: rgba(255, 255, 255, 1);
    transition: all 200ms ease;
}

.discord_join_button:hover {
    box-shadow: 0 0 60px #2332d8;
}

如果想了解更多关于transition属性的信息,请访问此链接:这里

英文:

you can achieve the "fade in" effect by specifying the transition property to the button base style. For example:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.discord_join_button {
    color: rgba(255, 255, 255, 1); 
    transition: all 200ms ease;
}

.discord_join_button:hover {
    box-shadow: 0 0 60px #2332d8; 
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;title&gt;Transition&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;button class=&quot;discord_join_button&quot;&gt;Hover me&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

If you want to know more about the transition property: here.

huangapple
  • 本文由 发表于 2023年2月19日 03:36:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定