What to do if hover doesn't work

藏色散人
Release: 2023-01-03 09:27:15
Original
9166 people have browsed it

Solution for hover not working: 1. Check and delete the space before ":hover"; 2. Check and modify the correct class name; 3. Check whether ":hover" is placed in ":hover" link" and ":visited", just modify the location.

What to do if hover doesn't work

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

There are several reasons why hover in css does not work:

1. Add a space before setting:hover:

For example,

<style type="text/css">
.one {
margin: 0 auto;
width: 400px;
height: 300px;
background: #ced05d;
}
.two {
margin: 0 auto;
width: 100px;
height: 100px;
background: #5a5aea;
}
.three {
margin: 0 auto;
width: 200px;
height: 100px;
background: #4b9c49;
}
.four {
margin: 0 auto;
width: 300px;
height: 100px;
background: #7b4141;
}
.one :hover {
background: #da56d0;
}
</style>
<body>
<h1>测试</h1>
<div class="one">
<div class="two">
</div>
<div class="three">
</div>
<div class="four">
</div>
</div>
</body>
Copy after login

you find that the mouse When the class is one, the background remains unchanged, but the background color of other divs inside one changes.

Explanation: Adding a space before hover will not have the effect of :hover, but the descendant elements will have: hover effect.

[Recommended learning: css video tutorial]

2. When the mouse passes over, let other elements change styles:

You will find at this time , only descendant elements and sibling elements (sibling elements immediately after the element) have an effect, other :hover will be invalid

3. The class name is written wrong;

4.: hover is placed before :link and :visited;

In the CSS definition, a:hover must be placed after a:link and a:visited to be valid.

In the CSS definition, a:active must be placed after a:hover to be valid.

The above is the detailed content of What to do if hover doesn't work. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!