Web Front-end
HTML Tutorial
Pure css to implement Magicline Navigation (underline animated navigation menu)_html/css_WEB-ITnose
Pure css to implement Magicline Navigation (underline animated navigation menu)_html/css_WEB-ITnose
When I was looking at other people’s websites, I saw an animation of a navigation menu. I thought it was very interesting, so I studied it carefully.
There are three types of animations I have seen so far: horizontal underline animation navigation, horizontal background animation navigation, and vertical animation navigation. Their implementation ideas are the same, and they all rely on the same-level universal selector "~" of CSS3.
I implemented it myself. This article briefly records the implementation ideas.
You can take a look at the final effect first: Click here for Demo
Implementation ideas
HTML structure
The HTML structure is not special, it is ul -> ; li:
<ul class="a"> <li class="n1"><a href="#">Navigator A</a></li> <li class="n2"><a href="#">Navigator B</a></li> <li class="n3 selected"><a href="#">Navigator C</a></li> <li class="n4"><a href="#">Navigator D</a></li> <li class="quebec"> </li></ul>
The last li is empty and will be used later.
CSS layout
Implement the basic style, not much explanation:
li { list-style: none outside; position: relative; z-index: 1; float: left; padding: 0 0 0 0; } li a { position: relative; top: 5px; display: block; margin: 0 0; border-bottom: 5px solid transparent; padding: 10px 0; text-align: center; text-decoration: none; } .selected a { border-bottom: 5px solid #cfd0d0; color: #340e56; }Implement the navigation underline
The animation part is implemented below.
The purple scroll bar below is achieved through the last li element that was left just now.
.quebec { position: absolute; bottom: -5px; left: 0; z-index: 3; margin: 0; border: 0; width: 5px; height: 5px; padding: 0; overflow: hidden; text-indent: -9999em; background: #511d7f; -webkit-transition-property: left, width; -moz-transition-property: left, width; -ms-transition-property: left, width; -o-transition-property: left, width; transition-property: left, width; -webkit-transition-duration: .5s; -moz-transition-duration: .5s; -ms-transition-duration: .5s; -o-transition-duration: .5s; transition-duration: .5s; }Use absolute positioning to position the last li.quebec below the navigation and set the width and height. Set transition so that animation can be achieved when we change left and width.
Mobile
When hovering over the navigation, li.quebec will position left below it. What achieves this effect is the CSS3 sibling universal selector "~"
For example, A ~ B matches any sibling B element after the A element.
.n1:hover ~ li.quebec { left: 0; width: 95px; } .n2:hover ~ li.quebec { left: 100px; width: 95px; } .n3:hover ~ li.quebec { left: 192px; width: 95px; } .n4:hover ~ li.quebec { left: 285px; width: 95px; }Here is a pure CSS underline animated navigation. Final effect: Demo view
Extension
After we implement horizontal underline animation navigation, the idea of implementing background moving animation navigation is the same, but it is the change of the height and width of li.quebec, background Transparency changes.
The same is true for vertical animated navigation, change the height and width of li.quebec, and control its position in the vertical direction through translateY.
In order to make the effect more dazzling, we can also change the color, background, transparency, etc. of li.quebec when hovering different li.
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1389
52
Is HTML easy to learn for beginners?
Apr 07, 2025 am 12:11 AM
HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.
The Roles of HTML, CSS, and JavaScript: Core Responsibilities
Apr 08, 2025 pm 07:05 PM
HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.
What is the purpose of the <progress> element?
Mar 21, 2025 pm 12:34 PM
The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati
What is the purpose of the <datalist> element?
Mar 21, 2025 pm 12:33 PM
The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159
What is an example of a starting tag in HTML?
Apr 06, 2025 am 12:04 AM
AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
What is the purpose of the <meter> element?
Mar 21, 2025 pm 12:35 PM
The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex
Understanding HTML, CSS, and JavaScript: A Beginner's Guide
Apr 12, 2025 am 12:02 AM
WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.
Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors?
Apr 04, 2025 pm 11:54 PM
GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...


