Overlay over image on hover

て烟熏妆下的殇ゞ 提交于 2020-01-04 07:46:13

问题


I am unsure of what I am doing wrong trying to get a transparent overlay to appear over an image on hover. Initially, I attempted a javascript approach, but that didn't work, so I figured I would try a more light-weight css approach.

Does anyone see why this is not working?

.section2-box {
  display: inline-block;
  width: 50%;
  height: 50%;
  border-bottom: 4px solid #FFF;
  border-right: 4px solid #FFF;
  box-sizing: border-box;
  position: relative;
}
.fadeHover {
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
}

.fadeHover:hover .overlay {
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 1;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
}

.fadeHover-title {
	font-family: 'Raleway', sans-serif;
	font-weight: 600;
	font-size: 1.3rem;
	color: #FFF;
	display: none;
}
.fadeHover-title.activeHover {
	opacity: 1;
}
.fadeHover-description {
	font-size: 1.1rem;
	color: #FFF;
	font-family: 'Open Sans', sans-serif;
	display: none;
}
.fadeHover-description.activeHover {
	opacity: 1;
}	
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="section2-box fadehover" id="section2box3">
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg">
  <div class="overlay">
    <h2 class="fadeHover-title">Option 1</h2>
    <h3 class="fadeHover-description">Description</h3>
  </div>
</div>

回答1:


Regardinf your question on the comment : change the text color of the element from a rgba with 0 alpha to a 1 alpha:

.section2-box {
  display: inline-block;
  width: 50%;
  height: 50%;
  border-bottom: 4px solid #FFF;
  border-right: 4px solid #FFF;
  box-sizing: border-box;
  position: relative;
}
.fadeHover {
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
}

.fadeHover .overlay {
  z-index: 1;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
}

.fadeHover-title {
	font-family: 'Raleway', sans-serif;
	font-weight: 600;
	font-size: 1.3rem;
	color: rgba(255,255,255,0);
  transition: color 0.5s;
}

.fadeHover:hover .fadeHover-title {
	color: rgba(255,255,255,1);
}
.fadeHover-description {
	font-size: 1.1rem;
	color: rgba(255,0,0,0);
  transition: color 0.5s;
}
.fadeHover:hover .fadeHover-description {
	color: rgba(255,0,0,1);
}
<div class="section2-box fadeHover" id="section2box3">
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg">
  <div class="overlay">
    <h2 class="fadeHover-title">Option 1</h2>
    <h3 class="fadeHover-description">Description</h3>
  </div>
</div>


来源:https://stackoverflow.com/questions/43549461/overlay-over-image-on-hover

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!