0

I need show an envelope icon when the user hovers over a button.

I used the pseudo class before to show the icon. When I change opacity in .btn-btn-envelope::before to 1, I still can't see the envelope icon.

.btn-pos {
  margin-top: 10px;
  float: right;
}

.btn-btn {
  border: none;
  background-color: #502030;
  color: #fff;
  padding: 10px 0;
  font-size: 15px;
  cursor: pointer;
  font-family: 'Lekton', sans-serif;
  text-align: center;
  display: inline-block;
  position: relative;
  overflow: hidden;
  width: 90px;
}

.btn-btn-envelope {
  transition: all 0.3s ease-in-out;
}

.btn-btn-envelope::before {
  content: url('https://image.flaticon.com/icons/png/128/1034/1034138.png');
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  top: 0;
  right: 0;
  opacity: 0;
  width: 15px;
  height: 100%;
}

.btn-btn-envelope:hover {
  text-indent: -20px;
}

.btn-btn-envelope:hover::before {
  opacity: 1;
  text-indent: 0px;
}
<div class="btn-pos">
  <input type="submit" value="Send" class="btn-btn btn-btn-envelope">
</div>

(fiddle)

MTCoster
  • 5,868
  • 3
  • 28
  • 49
michal
  • 1,534
  • 5
  • 28
  • 62
  • additionally to duplicate, your picture is black, so it's going to be hard to see it anyways with a black button – soulshined Feb 19 '19 at 21:58
  • How is this a duplicate the other answer is about jQuery this is all about CSS. – codeKracken Feb 19 '19 at 22:15
  • 1
    Here is a solution. Just add icon class to your input then in your CSS add .icon{background-image:url('https://image.flaticon.com/icons/png/128/1034/1034138.png'); background-size: 0; background-repeat: no-repeat; background-position: right;} .icon:hover{background-size: 25px 25px;} – codeKracken Feb 19 '19 at 22:17
  • 1
    Check it here. https://codepen.io/anon/pen/vbPpyO – codeKracken Feb 19 '19 at 22:18

0 Answers0