241

サムネイルの上にcssを付けてホバーすると、背景のグラデーションがフェードインするようにトランジションしようとしています。トランジションは機能しませんが、rgba()値に変更するだけで問題なく機能します。グラデーションはサポートされていませんか?私も画像を使ってみましたが、画像も遷移しません。

別の投稿のように、それが可能であることは知っていますが、どれほど正確に理解することはできません。ヘルプ>使用するCSSは次のとおりです。

#container div a {
  -webkit-transition: background 0.2s linear;
  -moz-transition: background 0.2s linear;
  -o-transition: background 0.2s linear;
  transition: background 0.2s linear;
  position: absolute;
  width: 200px;
  height: 150px;
  border: 1px #000 solid;
  margin: 30px;
  z-index: 2
}

#container div a:hover {
  background: -webkit-gradient(radial, 100 75, 100, 100 75, 0, from(rgba(0, 0, 0, .7)), to(rgba(0, 0, 0, .4)))
}
4

18 に答える 18

201

グラデーションはまだトランジションをサポートしていません(ただし、現在の仕様では、補間によるグラジエントトランジションのようにグラジエントをサポートする必要があるとされています)。

背景のグラデーションでフェードイン効果が必要な場合は、コンテナ要素に不透明度を設定し、不透明度を「遷移」する必要があります。

(グラデーションのトランジションをサポートするブラウザリリースがいくつかあります(例:IE10。2016年にIEでグラデーショントランジションをテストしましたが、当時は機能していたようですが、テストコードは機能しなくなりました。)

更新:2018年10月 接頭辞のない新しい構文を使用したグラデーション遷移[例:radial-gradient(...)]がMicrosoft Edge 17.17134で(再び?)動作することが確認されました。これがいつ追加されたのかわかりません。最新のFirefoxとChrome/Windows10ではまだ動作していません。

更新:2021年12月 これは、@ property回避策を使用する最近のChromiumベースのブラウザーで可能になりました(ただし、Firefoxでは機能しません)。以下の@mahozadの回答をご覧ください。

于 2011-07-01T00:55:49.217 に答える
113

回避策の1つは、背景の位置を移行して、グラデーションが変化している効果を与えることです。http: //sapphion.com/2011/10/css3-gradient-transition-with-background-position/

背景位置を使用したCSS3グラデーション遷移

CSSトランジションプロパティを使用してグラデーションを直接アニメーション化することはできませんが、background-positionプロパティをアニメーション化して、単純なグラデーションアニメーションを実現することは可能です。

このためのコードは非常に単純です。

#DemoGradient{  
    background: -webkit-linear-gradient(#C7D3DC,#5B798E);  
    background: -moz-linear-gradient(#C7D3DC,#5B798E);  
    background: -o-linear-gradient(#C7D3DC,#5B798E);  
    background: linear-gradient(#C7D3DC,#5B798E);  
  
    -webkit-transition: background 1s ease-out;  
    -moz-transition: background 1s ease-out;  
    -o-transition: background 1s ease-out;  
    transition: background 1s ease-out;  
  
    background-size:1px 200px;  
    border-radius: 10px;  
    border: 1px solid #839DB0;  
    cursor:pointer;  
    width: 150px;  
    height: 100px;  
}  
#DemoGradient:Hover{  
    background-position:100px;  
}  
<div id="DemoGradient"></div>  

于 2011-10-27T16:44:11.760 に答える
36

解決策は、背景位置を使用してグラデーション遷移を模倣することです。 このソリューションは、数か月前にTwitterBootstrapで使用されました。

アップデート

http://codersblock.blogspot.fr/2013/12/gradient-animation-trick.html?showComment=1390287622614

簡単な例を次に示します。

リンク状態

 .btn {
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 12px;
  font-weight: 300;
  position: relative;
  display: inline-block;
  text-decoration: none;
  color: #fff;
  padding: 20px 40px;
  background-image: -moz-linear-gradient(top, #50abdf, #1f78aa);
  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#50abdf), to(#1f78aa));
  background-image: -webkit-linear-gradient(top, #50abdf, #1f78aa);
  background-image: -o-linear-gradient(top, #50abdf, #1f78aa);
  background-image: linear-gradient(to bottom, #50abdf, #1f78aa);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff50abdf', endColorstr='#ff1f78aa', GradientType=0);
  background-repeat: repeat-y;
  background-size: 100% 90px;
  background-position: 0 -30px;
  -webkit-transition: all 0.2s linear;
     -moz-transition: all 0.2s linear;
       -o-transition: all 0.2s linear;
          transition: all 0.2s linear;
}

ホバー状態

.btn:hover {
   background-position: 0 0;
}
于 2013-03-19T12:20:50.847 に答える
22

それが価値があるもののために、ここにSassミックスインがあります:

使用法:

@include gradientAnimation(red, blue, .6s);

混入します:

@mixin gradientAnimation( $start, $end, $transTime ){
    background-size: 100%;
    background-image: linear-gradient($start, $end);
    position: relative;
    z-index: 100;
    &:before {
        background-image: linear-gradient($end, $start);
        content: "";
        display: block;
        height: 100%;
        position: absolute;
        top: 0; left: 0;
        opacity: 0;
        width: 100%;
        z-index: -100;
        transition: opacity $transTime;
    }
    &:hover {
        &:before {
            opacity: 1;
        }
    }
}

Dave LunnyのMediumに関するこの素晴らしい投稿からの抜粋:https ://medium.com/@dave_lunny/animating-css-gradients-using-only-css-d2fd7671e759

于 2018-07-09T04:54:37.353 に答える
20

2021:グラデーションをアニメーション化できるようになりました(FirefoxやSafariはまだできません)

Chrome 85EdgeOperaで@propertyルールのサポートが追加され、CSSでこれを実行できるようになりました。

@property --myColor1 {
  syntax: '<color>';
  initial-value: magenta;
  inherits: false;
}

@property --myColor2 {
  syntax: '<color>';
  initial-value: green;
  inherits: false;
}

残りは通常のCSSです。
変数を初期グラデーションカラーとして設定し、それらの変数の遷移も設定します。

div {
  /* Optional: change initial value of the variables */
  /* --myColor1: #f64; --myColor2: brown; */

  background: linear-gradient(var(--myColor1), var(--myColor2));
  transition: --myColor1 3s, --myColor2 3s;
}

次に、目的のルールで、変数に新しい値を設定します。

div:hover {  
  --myColor1: #f00;
  --myColor2: yellow;
}

@property --myColor1 {
  syntax: '<color>';
  initial-value: #0f0;
  inherits: false;
}

@property --myColor2 {
  syntax: '<color>';
  initial-value: rgb(40, 190, 145);
  inherits: false;
}

div {
  width: 200px;
  height: 100px;
  background: linear-gradient(var(--myColor1), var(--myColor2));
  transition: --myColor1 3s, --myColor2 3s;
}

div:hover {
  --myColor1: red;
  --myColor2: #E1AF2F;
}
<div>Hover over me</div>

ここで完全な説明と例を参照し、仕様についてはここ@propertyを参照してください。
@propertyルールは、CSSHoudiniテクノロジーの一部です。詳細については、ここここを参照し、このビデオを参照してください。

于 2020-09-11T14:17:34.073 に答える
16

私はそれが古い質問であることを知っていますが、誰かが純粋なCSSで私の解決方法を楽しんでいます。グラデーションは左から右にフェードします。

.contener{   
  width:300px;
  height:200px;
  background-size:cover;
  border:solid 2px black;
}
.ed {
    width: 0px;
    height: 200px;
    background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.75));
    position: relative;
    opacity:0;
    transition:width 20s, opacity 0.6s;
}

.contener:hover .ed{
    width: 300px;
    background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.75));
    position: relative;
    opacity:1;
    transition:width 0.4s, opacity 1.1s;
    transition-delay: width 2s;
    
    animation-name: gradient-fade;
    animation-duration: 1.1s;   
    -webkit-animation-name: gradient-fade; /* Chrome, Safari, Opera */
    -webkit-animation-duration: 1.1s; /* Chrome, Safari, Opera */
}




/* ANIMATION */
@-webkit-keyframes gradient-fade {
    0%   {background:linear-gradient(to right, rgba(0,0,255,0), rgba(255,0,0,0));}
    2%  {background:linear-gradient(to right, rgba(0,0,255,0.01875), rgba(255,0,0,0));}
    4%  {background:linear-gradient(to right, rgba(0,0,255,0.0375), rgba(255,0,0,0.0));}
    6%  {background:linear-gradient(to right, rgba(0,0,255,0.05625), rgba(255,0,0,0.0));}
    8% {background:linear-gradient(to right, rgba(0,0,255,0.075), rgba(255,0,0,0));}
    10%  {background:linear-gradient(to right, rgba(0,0,255,0.09375), rgba(255,0,0,0));}
    12%   {background:linear-gradient(to right, rgba(0,0,255,0.1125), rgba(255,0,0,0));}
    14%  {background:linear-gradient(to right, rgba(0,0,255,0.13125), rgba(255,0,0,0));}
    16%  {background:linear-gradient(to right, rgba(0,0,255,0.15), rgba(255,0,0,0));}
    18%  {background:linear-gradient(to right, rgba(0,0,255,0.16875), rgba(255,0,0,0));}
    20% {background:linear-gradient(to right, rgba(0,0,255,0.1875), rgba(255,0,0,0));}
    22%  {background:linear-gradient(to right, rgba(0,0,255,0.20625), rgba(255,0,0,0.01875));}
    24%   {background:linear-gradient(to right, rgba(0,0,255,0.225), rgba(255,0,0,0.0375));}
    26%  {background:linear-gradient(to right, rgba(0,0,255,0.24375), rgba(255,0,0,0.05625));}
    28%  {background:linear-gradient(to right, rgba(0,0,255,0.2625), rgba(255,0,0,0.075));}
    30%  {background:linear-gradient(to right, rgba(0,0,255,0.28125), rgba(255,0,0,0.09375));}
    32% {background:linear-gradient(to right, rgba(0,0,255,0.3), rgba(255,0,0,0.1125));}
    34%  {background:linear-gradient(to right, rgba(0,0,255,0.31875), rgba(255,0,0,0.13125));}
    36%   {background:linear-gradient(to right, rgba(0,0,255,0.3375), rgba(255,0,0,0.15));}
    38%  {background:linear-gradient(to right, rgba(0,0,255,0.35625), rgba(255,0,0,0.16875));}
    40%  {background:linear-gradient(to right, rgba(0,0,255,0.375), rgba(255,0,0,0.1875));}
    42%  {background:linear-gradient(to right, rgba(0,0,255,0.39375), rgba(255,0,0,0.20625));}
    44% {background:linear-gradient(to right, rgba(0,0,255,0.4125), rgba(255,0,0,0.225));}
    46%  {background:linear-gradient(to right, rgba(0,0,255,0.43125),rgba(255,0,0,0.24375));}
    48%   {background:linear-gradient(to right, rgba(0,0,255,0.45), rgba(255,0,0,0.2625));}
    50%  {background:linear-gradient(to right, rgba(0,0,255,0.46875), rgba(255,0,0,0.28125));}
    52%  {background:linear-gradient(to right, rgba(0,0,255,0.4875), rgba(255,0,0,0.3));}
    54%   {background:linear-gradient(to right, rgba(0,0,255,0.50625), rgba(255,0,0,0.31875));}
    56%  {background:linear-gradient(to right, rgba(0,0,255,0.525), rgba(255,0,0,0.3375));}
    58%  {background:linear-gradient(to right, rgba(0,0,255,0.54375), rgba(255,0,0,0.35625));}
    60%  {background:linear-gradient(to right, rgba(0,0,255,0.5625), rgba(255,0,0,0.375));}
    62% {background:linear-gradient(to right, rgba(0,0,255,0.58125), rgba(255,0,0,0.39375));}
    64%  {background:linear-gradient(to right,rgba(0,0,255,0.6), rgba(255,0,0,0.4125));}
    66%   {background:linear-gradient(to right, rgba(0,0,255,0.61875), rgba(255,0,0,0.43125));}
    68%  {background:linear-gradient(to right, rgba(0,0,255,0.6375), rgba(255,0,0,0.45));}
    70%  {background:linear-gradient(to right, rgba(0,0,255,0.65625), rgba(255,0,0,0.46875));}
    72%  {background:linear-gradient(to right, rgba(0,0,255,0.675), rgba(255,0,0,0.4875));}
    74% {background:linear-gradient(to right, rgba(0,0,255,0.69375), rgba(255,0,0,0.50625));}
    76%  {background:linear-gradient(to right, rgba(0,0,255,0.7125), rgba(255,0,0,0.525));}
    78%   {background:linear-gradient(to right, rgba(0,0,255,0.73125),,rgba(255,0,0,0.54375));}
    80%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.5625));}
    82%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.58125));}
    84%  {background:linear-gradient(to right, rgba(0,0,255,0.75),rgba(255,0,0,0.6));}
    86% {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.61875));}
    88%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.6375));}
    90%   {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.65625));}
    92%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.675));}
    94%  {background:linear-gradient(to right, rgba(0,0,255,0.75),rgba(255,0,0,0.69375));}
    96%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.7125));}
    98% {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.73125),);}
    100%  {background:linear-gradient(to right, rgba(0,0,255,0.75), rgba(255,0,0,0.75));}
}
<div class="contener" style="">
  <div class="ed"></div>
</div>

于 2016-07-01T11:50:59.790 に答える
9

::以前は、CSS疑似要素で簡単にトリックを実行できます。

あなたがしなければならないのは、不透明度がゼロの::before疑似要素を使用することだけです。

:hoverで、不透明度を1に切り替えます。いくつかの簡単な手順に従うと、トランジションが機能するはずです。


.element {
  position: relative;
  width: 500px;
  height: 400px;
  background-image: linear-gradient(45deg, blue, aqua);
  z-index: 2;
}

.element::before {
  position: absolute;
  content: "";
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image: linear-gradient(to bottom, red, orange);
  z-index: 1;
  opacity: 0;
  transition: opacity 0.4s linear;
}

.element:hover::before {
  opacity: 1;
}


  1. 要素をターゲットにし、background-imageを使用してデフォルトのグラデーションを設定します
  2. 同じ要素をターゲットにするには、:: beforeを使用して、 background-imageで次のグラデーションを設定し、不透明度をゼロに 設定します
  3. 今すぐ使用:hover :: before 、不透明度を1に設定
  4. :: beforeブロック の使用に戻ります:
    • 絶対位置
    • コンテンツ: ""
    • デフォルトの要素よりも低いz-index
    • をゼロに設定します
    • 不透明度プロパティをターゲットとする遷移属性を設定します
  5. これですべてが完了し、任意の期間/遅延/タイミング機能でトランジションを微調整できます!
于 2021-02-17T04:27:47.320 に答える
6

あなたの質問のcssコードに基づいて、私は次のようにコードを試しました、そしてそれは私のために働きます(コードスニペットを実行してください)、そしてあなた自身で試してください:

#container div a {
  display: inline-block;
  margin-top: 10%;
  padding: 1em 2em;
  font-size: 2em;
  color: #fff;
  font-family: arial, sans-serif;
  text-decoration: none;
  border-radius: 0.3em;
  position: relative;
  background-color: #ccc;
  background-image: linear-gradient(to top, #C0357E, #EE5840);
  -webkit-backface-visibility: hidden;
  z-index: 1;
}
     
#container div a:after {
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0.3em;
  background-image: linear-gradient(to top, #6d8aa0, #343436);
  transition: opacity 0.5s ease-out;
  z-index: 2;
  opacity: 0;
}
    
#container div a:hover:after {
  opacity: 1;
}
#container div a span {
  position: relative;
  z-index: 3;
}
<div id="container"><div><a href="#"><span>Press Me</span></a></div></div>

あなたの質問のcssコードに基づいて、私は次のようなコードを試しました、そしてそれは私のために働きます、そしてあなた自身で試してください:

    #container div a {
  display: inline-block;
  margin-top: 10%;
  padding: 1em 2em;
  font-size: 2em;
  color: #fff;
  font-family: arial, sans-serif;
  text-decoration: none;
  border-radius: 0.3em;
  position: relative;
  background-color: #ccc;
  background-image: linear-gradient(to top, #C0357E, #EE5840);
  -webkit-backface-visibility: hidden;
  z-index: 1;
}

#container div a:after {
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0.3em;
  background-image: linear-gradient(to top, #6d8aa0, #343436);
  transition: opacity 0.5s ease-out;
  z-index: 2;
  opacity: 0;
}

#container div a:hover:after {
  opacity: 1;
}
#container div a span {
  position: relative;
  z-index: 3;
}

それはあなたのために働きますか?必要に応じて色を変更してください:)

于 2017-08-31T21:29:42.540 に答える
5

グラデーショントランジションの部分的な回避策は、インセットボックスシャドウを使用することです。ボックスシャドウ自体または背景色のい​​ずれかをトランジションできます。たとえば、背景と同じ色のインセットボックスシャドウを作成し、背景色にトランジションを使用すると、錯覚が生じます。その無地の背景が放射状のグラデーションに変化しています

.button SPAN {
    padding: 10px 30px; 
    border: 1px solid ##009CC5;

    -moz-box-shadow: inset 0 0 20px 1px #00a7d1;
    -webkit-box-shadow: inset 0 0 20px 1px#00a7d1;
    box-shadow: inset 0 0 20px 1px #00a7d1; 

    background-color: #00a7d1;
    -webkit-transition: background-color 0.5s linear;
    -moz-transition: background-color 0.5s linear;
    -o-transition: background-color 0.5s linear;
    transition: background-color 0.5s linear;
}

.button SPAN:hover {
    background-color: #00c5f7; 
}
于 2013-09-25T13:09:55.763 に答える
4

以下では、アンカータグに子と孫があります。孫は遠い背景勾配を持っています。近くの背景にある子は透明ですが、移行するグラデーションがあります。ホバーすると、子供の不透明度は1秒間で0から1に移行します。

CSSは次のとおりです。

.bkgrndfar {
  position:absolute;
  top:0;
  left:0;
  z-index:-2;
  height:100%;
  width:100%;
  background:linear-gradient(#eee, #aaa);
}

.bkgrndnear {
  position:absolute;
  top:0;
  left:0;
  height:100%;
  width:100%;
  background:radial-gradient(at 50% 50%, blue 1%, aqua 100%);
  opacity:0;
  transition: opacity 1s;
}

a.menulnk {
  position:relative;
  text-decoration:none;
  color:#333;
  padding: 0 20px;
  text-align:center;
  line-height:27px;
  float:left;
}

a.menulnk:hover {
  color:#eee;
  text-decoration:underline;
}

/* This transitions child opacity on parent hover */
a.menulnk:hover .bkgrndnear {
  opacity:1;
}

そして、これはHTMLです。

<a href="#" class="menulnk">Transgradient
<div class="bkgrndfar">
  <div class="bkgrndnear">
  </div>
</div>
</a>

上記は、最新バージョンのChromeでのみテストされています。これらは、ホバー前、ホバーの途中、ホバー上で完全に遷移した画像です。

前 中途半端 後

于 2013-07-13T22:23:07.747 に答える
4

opacityプロパティを変更するが、疑似要素を活用することで、あるグラデーションから別のグラデーションにフェードすることを実現する、codepenの優れたハックを見つけました。彼がしている:afterのは、実際の要素の不透明度を変更すると、:after要素が表示されてフェードのように見えるように設定することです。共有すると便利だと思いました。

元のcodepen:http ://codepen.io/sashtown/pen/DfdHh

.button {
  display: inline-block;
  margin-top: 10%;
  padding: 1em 2em;
  font-size: 2em;
  color: #fff;
  font-family: arial, sans-serif;
  text-decoration: none;
  border-radius: 0.3em;
  position: relative;
  background-color: #ccc;
  background-image: linear-gradient(to top, #6d8aa0, #8ba2b4);
  -webkit-backface-visibility: hidden;
  z-index: 1;
}
.button:after {
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0.3em;
  background-image: linear-gradient(to top, #ca5f5e, #d68584);
  transition: opacity 0.5s ease-out;
  z-index: 2;
  opacity: 0;
}
.button:hover:after {
  opacity: 1;
}
.button span {
  position: relative;
  z-index: 3;
}
body {
  text-align: center;
  background: #ddd;
}
<a class="button" href="#"><span>BUTTON</span></a>

于 2015-03-16T16:42:47.243 に答える
4

divを3D球のように表示し、色を遷移させたいと思いました。グラデーションの背景色は(まだ)移行しないことを発見しました。要素の前に(z-indexを使用して)放射状のグラデーションの背景を配置し、背景は無地に移行しました。

/* overlay */
z-index : 1;
background : radial-gradient( ellipse at 25% 25%, rgba( 255, 255, 255, 0 ) 0%, rgba( 0, 0, 0, 1 ) 100% );

次に、div.ballその下:

transition : all 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);

次に、と出来上がりの背景色を変更しましたdiv.ball

https://codepen.io/keldon/pen/dzPxZP

于 2017-07-26T10:33:36.930 に答える
3

ここでの回答のいくつかで説明されているように、いくつかの積み重ねられたグラデーションの不透明度のトランジションを使用して、グラデーション間のトランジションを偽造することができます。

グラデーションのあるCSS3アニメーション

ここで説明するように、代わりに位置を移行することもできます。

背景位置を使用したCSS3グラデーション遷移

ここにいくつかのより多くのテクニック:

CSS3グラデーションのアニメーション

于 2012-09-29T03:33:07.720 に答える
3

:beforeと:after(ie9 +)を使用してみてください

#wrapper{
    width:400px;
    height:400px;
    margin:0 auto;
    border: 1px #000 solid;
    position:relative;}
#wrapper:after,
#wrapper:before{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    content:'';
    background: #1e5799;
    background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8));
    background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
    background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
    background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
    background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
    opacity:1;
    z-index:-1;
    -webkit-transition: all 2s ease-out;
    -moz-transition: all 2s ease-out;
    -ms-transition: all 2s ease-out;
    -o-transition: all 2s ease-out;
    transition: all 2s ease-out;
}
#wrapper:after{
    opacity:0;
    background: #87e0fd;
    background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#87e0fd), color-stop(40%,#53cbf1), color-stop(100%,#05abe0));
    background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
    background: -o-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
    background: -ms-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
    background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
}
#wrapper:hover:before{opacity:0;}
#wrapper:hover:after{opacity:1;}
于 2013-07-25T13:10:44.953 に答える
2

述べたように。グラデーションは現在、CSSトランジションではサポートされていません。ただし、場合によっては、色の1つを透明に設定して、他のラッピング要素の背景色が透けて見えるようにし、代わりにそれを遷移させることで、この問題を回避できます。

于 2012-08-06T10:38:27.623 に答える
2

私は仕事でこれを使用しています:)IE6+ https://gist.github.com/GrzegorzPerko/7183390

<element class="ahover"><span>Text</span></a>テキスト要素を使用する場合は忘れないでください。

.ahover {
    display: block;
    /** text-indent: -999em; ** if u use only only img **/
    position: relative;
}
.ahover:after {
    content: "";
    height: 100%;
    left: 0;
    opacity: 0;
    position: absolute;
    top: 0;
    transition: all 0.5s ease 0s;
    width: 100%;
    z-index: 1;
}
.ahover:hover:after {
    opacity: 1;
}
.ahover span {
    display: block;
    position: relative;
    z-index: 2;
}
于 2013-10-27T15:26:38.800 に答える
2

これを行う公式の方法がまだないので、別のビューを投稿することを傷つけることはできません。背景の放射状グラデーションと遷移速度を定義できる軽量のjQueryプラグインを作成しました。この基本的な使用法では、requestAnimationFrameで最適化されてフェードインします(非常にスムーズ):

$('#element').gradientFade({

    duration: 2000,
    from: '(20,20,20,1)',
    to: '(120,120,120,0)'
});

http://codepen.io/Shikkediel/pen/xbRaZz?editors=001

元の背景とすべてのプロパティをそのまま保持します。設定としてハイライトトラッキングもあります:

http://codepen.io/Shikkediel/pen/VYRZZY?editors=001

于 2015-01-06T00:09:00.440 に答える
0

よりクリーンな解決策は、背景色を設定し、マスク画像を使用することです。

#container div a {
  background-color: blue;
  transition: background 0.2s linear;
  width: 200px;
  height: 150px;
  mask-image: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, .7), rgba(0, 0, 0, .4));
}

#container div a:hover { 
  background-color: red;
}
于 2022-01-07T15:35:29.600 に答える