


Use:hover pseudo-class to replace js's hover event_html/css_WEB-ITnose
To make a secondary menu, if you want to move the mouse up to display the submenu, move the mouse out to hide the submenu, or other similar needs, first I will think of using jquery's hover event, such as:
$(".nav").hover(function(){ $("sub-nav").addClass("show");},function(){ $("sub-nav").removeClass("show");});
The first function implements the style of moving the mouse up, and the second function implements the style of moving the mouse away, thus realizing a simple drop-down menu function.
I have been doing this without any problems before, but I encountered a problem yesterday: when the element already has a click event to implement this function, and then use the hover event to implement the same function, the hover event will affect the click event and be removed. Click event function. For example:
A navigation, add current style to the currently clicked navigation, and then add a current event to the current element that the mouse moves to, then use the hover event, and the current style added by clicking will Affected by the hover event, and clicking again to add the style is invalid.
: hover pseudo-class
After struggling for a long time, I asked a colleague for advice. The colleague said that there is no need to use the hover event. It can be solved by using the pseudo-class, so in Under her guidance, I suddenly became enlightened.
.nav li.current,.nav li:hover{ //css code }
current is the currently required style, and then use :hover to share the same style with current. A simple conversion of ideas can solve the problem. In the same way, the menu displays the problem:
.nav:hover .sub-nav{ display:block;}
Summary: Sometimes you need to change your thinking and find the simplest way to solve the problem instead of being entangled in the problem all the time.

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











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.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...
