A pseudo-class :hover
is a type of selector that happens only when the mouse is over the specified element.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.post {
width: 200px;
height: 200px;
background-color: red;
}
.post:hover {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div class="post"></div>
</body>
</html>
This simple example above shows perfectly what I just said, :hover
it will only happen when mouse is on top of the element then if you put the mouse more the less 190px
on the x-axis and 5px
on the y axis, for example, you will see that the div
will be kind of flashing this because the div
was defined as width: 200px
and height: 200px
and when you pass the mouse over it will be width: 100px
and height: 100px
, but at the same time that I move the mouse over I’m also taking off so it gets in this nasty state.
In this case you could use Javascript, but like you said.
css only
Then you would have to use the example from above, but just a sample of how it would be with the Javascript.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.post {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="post"></div>
<script>
var div = window.document.querySelector(".post");
div.addEventListener("mouseout", saiu);
function saiu() {
div.style.width = "100px";
div.style.height = "100px";
}
</script>
</body>
</html>
Very simple, no bug, no nothing, working perfectly so get ready to choose one from above :).
I think only with Javascript
– Vinicius De Jesus
You want the element to decrease and be small even after you take the mouse off it and stay like this forever?
– hugocsl
Opa I can decrease normally when the person takes the mouse, is that I made an animation to decrease and I wanted to apply it when only the person took the mouse from above
– arthurguedes375