Home >Web Front-end >CSS Tutorial >How to achieve div flickering with CSS

How to achieve div flickering with CSS

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-09 17:05:036812browse

In css, you can use the "@keyframes" rule and the animation attribute to achieve the div flashing effect; you only need to first use "@keyframes" to create an animation with a flashing effect; then use the animation attribute to set the time required for the animation , speed and times, etc.

How to achieve div flickering with CSS

The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.

The rendering is as follows

How to achieve div flickering with CSS

The code is as follows

@keyframes fade {
    from {        
    opacity: 1.0;    
    }
    50% {        
    opacity: 0.4;    
    }
    to {        
    opacity: 1.0;    
    }
}
@-webkit-keyframes fade {    
    from {        
    opacity: 1.0;    
    }
    50% {        
    opacity: 0.4;    
    }
    to {        
    opacity: 1.0;    
    }
}
.headerBox {    
    color: #fff;    
    padding: 10px;    
    font-size: 15px;    
    height: 60px;    
    animation: fade 600ms infinite;    
    -webkit-animation: fade 600ms infinite;
}

Just set the headerBox style to the div

Recommended learning: css video tutorial

The above is the detailed content of How to achieve div flickering with CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn