Css淡入淡出

时间:2014-11-20 11:41:56

标签: css blink

我正在尝试制作div闪光灯,但我不希望它内部的文字闪烁,只是按钮本身。我不知道怎么能解决这个问题。我希望这是有道理的,任何人都可以帮忙吗?

以下是代码:

@-moz-keyframes blink {0%{opacity:1;} 50%{opacity:0.5;} 100%{opacity:1;}} /* Firefox */
@-webkit-keyframes blink {0%{opacity:1;} 50%{opacity:0.5;} 100%{opacity:1;}} /* Webkit */
@-ms-keyframes blink {0%{opacity:1;} 50%{opacity:0.5;} 100%{opacity:1;}} /* IE */
@keyframes blink {0%{opacity:1;} 50%{opacity:0.5;} 100%{opacity:1;}} /* Opera */

.download {
    background-color: red;
    padding: 15px 15px 15px 15px;
    text-align:center;
    margin-bottom: 4px;
    font-size: 24px;
    border-radius: 5px;
    -moz-transition:all 0.5s ease-in-out;
    -webkit-transition:all 0.5s ease-in-out;
    -o-transition:all 0.5s ease-in-out;
    -ms-transition:all 0.5s ease-in-out;
    transition:all 0.5s ease-in-out; 
    -moz-animation:blink normal 1.5s infinite ease-in-out; /* Firefox */
    -webkit-animation:blink normal 1.5s infinite ease-in-out; /* Webkit */
    -ms-animation:blink normal 1.5s infinite ease-in-out; /* IE */
    animation:blink normal 1.5s infinite ease-in-out; /* Opera */
}
<div class="download">DOWNLOAD TRIAL</div>

2 个答案:

答案 0 :(得分:13)

JSfiddle Demo

opacity会影响div及其所有孩子。我怀疑你需要的是带有alpha(透明度)组件的背景颜色。所以......在背景上使用RGBA颜色

@keyframes blink {
    0% {
        rgba(255,0,0,1)
    }
    50% {
        rgba(255,0,0,0.5)
    }
    100% {
        rgba(255,0,0,1)
    }
}

答案 1 :(得分:0)

若干年后,你可以使用这个可爱的眨眼和淡化效果

.blink {
    -webkit-animation: blink 2s infinite both;
            animation: blink 2s infinite both;
}

@-webkit-keyframes blink {
  0%,
  50%,
  100% {
    opacity: 1;
  }
  25%,
  75% {
    opacity: 0;
  }
}
@keyframes blink {
  0%,
  50%,
  100% {
    opacity: 1;
  }
  25%,
  75% {
    opacity: 0;
  }
}
<div class="blink">FADE AND BLINK!</div>