Can I disable a div using css?

Asked

Viewed 1,783 times

1

So I created two div inside each other and my idea was this: I wanted to leave a div inactive, and when I leave the mouse on one, the other appears.

The command I used for this is opacity: 0; to make it invisible and when I leave the mouse on top I put the command opacity: 1; for it to appear. Only that I wanted only when you hover over the div #boot it appears. I can do it for css?

the code is this:

#botao {
  position: relative;
  float: left;
  height: 20px;
  width: 20px;
  background-image: url(../img/wats.jpg);
  margin-top: 7px;
  margin-left: 4px;
  transition: all 0.5s ease;
}
a.botao-link {
  display: block;
  height: 100%;
  width: 100%;
  text-decoration: none;
}
#botao:hover {
  background-image: url(../img/wats-hover.jpg);
  transition: all 0.1s ease;
}
#comentario {
  text-align: center;
  position: relative;
  top: -22px;
  left: 30px;
  padding: 2px;
  line-height: 20px;
  background: #333;
  color: #fff;
  display: block;
  width: 120px;
  opacity: 0;
  -webkit-transition: all 300ms ease;
  -moz-transition: all 300ms ease;
  -ms-transition: all 300ms ease;
  -o-transition: all 300ms ease;
  transition: all 300ms ease;
  -moz-border-radius: 7px;
  -webkit-border-radius: 7px;
  border-radius: 7px;
}
#botao:hover #comentario {
  opacity: 1;
<div id="botao"><a href="#" class="wats-link"> botao </a>
  <div id="comentario">Comentário</div>

1 answer

2

Just use it instead:

#botao:hover #comentario {
  opacity: 1;
}

That:

#botao a:hover + #comentario {
  opacity: 1;
}

So the Hover will be on link and not in the div, as a whole.

Use the seletor + of css, to select the element in sequence, then the div#comentario should be the element after the link.

So you don’t "deactivate" the div, just changes the target no :Hover`, of the parent element (which encompassed both the link for the balloon), for the link.

Demo

#botao {
  position: relative;
  float: left;
  height: 20px;
  width: 20px;
  background-image: url(../img/wats.jpg);
  margin-top: 7px;
  margin-left: 4px;
  transition: all 0.5s ease;
}

a.botao-link {
  display: block;
  height: 100%;
  width: 100%;
  text-decoration: none;
}

#botao:hover {
  background-image: url(../img/wats-hover.jpg);
  transition: all 0.1s ease;
}

#comentario {
  text-align: center;
  position: relative;
  top: -22px;
  left: 30px;
  padding: 2px;
  line-height: 20px;
  background: #333;
  color: #fff;
  display: block;
  width: 120px;
  opacity: 0;
  -webkit-transition: all 300ms ease;
  -moz-transition: all 300ms ease;
  -ms-transition: all 300ms ease;
  -o-transition: all 300ms ease;
  transition: all 300ms ease;
  -moz-border-radius: 7px;
  -webkit-border-radius: 7px;
  border-radius: 7px;
}

#botao a:hover+#comentario {
  opacity: 1;
}
<div id="botao">
  <a href="#" class="wats-link"> botao </a>
  <div id="comentario">Comentário</div>
</div>

  • Thank you so much for the tip.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.