首页 > 解决方案 > 使用伪类之前无法在输入按钮悬停中显示图标

问题描述

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

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

.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>

小提琴

标签: htmlcss

解决方案


推荐阅读