Can I disable a div using css?

1

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

The command I used for this is opacity: 0; to make it invisible and when I left the mouse on top put the command opacity: 1; for it to appear. Only I wanted it only when the mouse is passed over the div #botao it appears.   Can I do this by 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>
    
asked by anonymous 22.10.2016 / 14:41

1 answer

2

Just use instead:

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

That:

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

So the hover will be in link and not in the div as a whole.

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

So, you do not "disable" the div , just change the target in the ': hover' of the parent element (which encompassed both link and balloon), just to 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>
    
22.10.2016 / 15:26