Home  >  Article  >  Web Front-end  >  What to do if hover doesn't work

What to do if hover doesn't work

藏色散人
藏色散人Original
2021-03-03 10:40:429199browse

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>

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!

Statement:
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