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
Table of contents 0x0 Introduction 0x1 Installati...
Unicode Signature BOM - What is the BOM? BOM is th...
The form elements with visibility=hidden and displ...
Nginx is a high-performance website server and re...
This article uses the crontab command in the Linu...
A static node is fixed on a machine and is starte...
Here is an example code for using regular express...
1. First, double-click the vmware icon on the com...
Cooper talked about the user's visual path, w...
Using the Vue language and element components, we...
As we all know, mailto is a very practical HTML ta...
Secondly, the ranking of keywords is also related ...
1. Check the character set of the database The ch...
Use scenarios: The jump path needs to be dynamica...
Add the following code to the CSS style of the el...