html - 使用不透明度的 CSS 过渡淡出不起作用

标签 html css

我试图让一个 div 在鼠标悬停时图像淡出(所以你只能看到后面的灰色背景)并且一些文本淡入。我一直在尝试使用 CSS 过渡来做到这一点,但是不透明度没有似乎发生了变化(即我仍然可以看到背景图像)。

HTML:

<div id='options'>
  <div class='option'>
    <div class='back-option'>
    </div>
    <div class='front-option'>
      Add post
    </div>
  </div>
</div>

CSS:

#options {
  font-family: 'Segoe UI', 'Arial', sans-serif;
}

.option {
  position: relative;
  width: 6.25em;
  height: 6.25em;
  border-radius: 5px;
  cursor: pointer;
  background-color: #363636;
}

.back-option {
  position: absolute;
  width: 6.25em;
  height: 6.25em;
  border-radius: 5px;
  background-image: url(http://png-5.findicons.com/files/icons/2672/pixel_ui/16/add.png);
  background-size: contain;
  -webkit-box-shadow: inset 0px 0px 0px 2px rgba(0,0,0,0.75);
  -moz-box-shadow: inset 0px 0px 0px 2px rgba(0,0,0,0.75);
  box-shadow: inset 0px 0px 0px 2px rgba(0,0,0,0.75);
  opacity: 1;
  transition: opacity 0.5s;
}
.back-option:hover {
  opacity: 0;
}

.front-option {
  position: absolute;
  width: 6.25em;
  height: 6.25em;
  border-radius: 5px;
  color: #FFFFFF;
  font-weight: bold;
  text-align: center;
  line-height: 6.25em;
  opacity: 0;
  transition: opacity 0.5s;
}
.front-option:hover {
  opacity: 1;
}

这是一个JSBin of it .

最佳答案

悬停未触发,因为 div 位于顶部。我只是修改了 css 来检测悬停在其父项上。

.option:hover .back-option {
  opacity: 0;
}

实例:http://jsbin.com/cucadami/4/edit

关于html - 使用不透明度的 CSS 过渡淡出不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22896952/

相关文章:

jQuery 模糊悬停效果问题

html - 溢出:隐藏和 % 高度

html - 更改特定的输入颜色文本

javascript - Selenium (Java): Retrieve value from disabled input text field

html - 将尺寸属性用于响应式图像

html - 使用 WebDriver 单击 <div class > 链接

javascript - 响应地将图像定位在背景图像上的特定目标处

php - 如何在表单的文本字段中输入 'split' 个单词并在数据库中查询每个单词

html - 使链接图标与最后一个词断开

html - 背景图片不显示