使用伪类beofre无法在输入按钮悬停中显示图标

时间:2019-02-19 21:42:08

标签: html css

当用户将鼠标悬停在按钮上时,我需要显示一个信封图标。

我使用伪类before来显示图标。当我将opacity中的.btn-btn-envelope::before更改为1时,仍然看不到信封图标。

.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

0 个答案:

没有答案