This article introduces the sample code of CSS3 transition to achieve underline, which is shared with you as follows: Take a look at our demo here Understanding transition This is a new style added in CSS3 that can achieve animation transition. Often used when adding some effect to transition from one style to another. The transition property
transition: width 1s linear 2s; /*Abbreviated example*/ /*Equivalent to the following*/ transition-property: width; transition-duration: 1s; transition-timing-function: linear; transition-delay: 2s; Transform attributes
Achieve the effect we need Of course, I will just post the code here, and there are comments in the code for easy understanding. /*css code*/ h2{ position: relative; padding: 15px; text-align: center; } button{ width: 100px; height: 40px; border-radius: 15px; border: none; background: #188FF7; color: #fff; outline: none; cursor: pointer; font-weight: bold; } button:hover{ background: #188EA7; } .container{ width: 600px; display: flex; flex-direction: column; align-items: center; margin: 0 auto; } .line{ position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; transition: transform .5s; background: #188EA7; color: #188EA7; transform: scaleX(0); z-index: 1111; } @keyframes changeColor1{ from{ color: #000; } to{ color: #188EA7; } } @keyframes changeColor2{ from{ color: #188EA7; } to{ color: #000; } } <!--html code--> <div class="container"> <h2 id="title"> Baidu Front-end Academy<i class="line" id="line"></i> </h2> <button id="change">Change</button> </div> //js part of the code (function () { let btn = document.getElementById('change'); let h2 = document.getElementById('title'); let line = document.getElementById('line'); let count = 0; btn.onclick = function () { if(count%2===0){ line.style.transform = "scaleX(1)"; h2.style.animation = "changeColor1 1s"; h2.style.color = "#188EA7"; count++; }else{ line.style.transform = "scaleX(0)"; h2.style.animation = "changeColor2 1s"; h2.style.color = "#000"; count++; } } })(); Summarize So far we have fully presented this effect, and we have also learned the transition and tranform properties in CSS3. Of course, some HTML and CSS basics are required to complete this animation. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Solve the problem of insufficient docker disk space
>>: Introduction to Common XHTML Tags
1. How to monitor MySQL deadlocks in production e...
During my internship in my senior year, I encount...
In the actual projects I participated in, I found...
Table of contents 1. Basic storage of files and d...
I am currently learning about Redis and container...
Preface Creating shortcuts in Linux can open appl...
Table of contents Preface The relationship betwee...
MySQL trigger syntax details: A trigger is a spec...
Table of contents Preface 1. scp usage 2. Use sft...
Table of contents Cycle comparison usage Summariz...
1. Introduction MySQL Group Replication (MGR for ...
Table of contents Vue3 encapsulation message prom...
Implementation ideas: First of all, the alarm inf...
Getting Started with JavaScript JavaScript is a l...
HTML web page list tag learning tutorial. In HTML ...