html - 背景悬停不出现在标题后面

标签 html css

我的编码问题是我希望图像标题在鼠标悬停时保持固定,但彩色背景只出现在标题下方而不是标题后面。如果我能让背景一直在标题后面,而不是在鼠标悬停在标题下方。我附上了几张图片,说明了当前的问题以及我希望的解决方案。我还附上了一些 HTML 和 CSS 编码示例,因此您也可以查看代码。谢谢!

.section{
	margin-top: -70px;
	margin-right: 225px;
	margin-left: 217px;
}
/*Portfolio Gallery*/
.view {
  position: relative;
  margin: 10px 0px 10px 10px;
  display: block;
  float: left;
  border: 10px solid #909090;
  overflow: hidden;
  text-align: center;
  background-image: url("../images/over1.jpg");
  border-radius: 50%;
   -moz-box-shadow:    inset 0 0 10px #000000;
   -webkit-box-shadow: inset 0 0 10px #000000;
   box-shadow:         inset 0 0 10px #000000;
  max-width: 30.26%;
	height: 300px;
}

.view .mask,
.view .content {
  overflow: hidden;
  top: 0;
  left: 0
}

.view h2 {
  text-transform: uppercase;
  text-decoration: underline;
  border: 1px solid #000000;
  color: #FFFFFF;
  font-weight: 900;
  text-align: center;
  font-size: 30px;
  padding: 10px;
  background:#000000;
  margin: 50px 0 0 0;
  overflow: hidden;
}

.view p {
 position: relative;
 display: block;
  font-family: Merriweather, serif;
  font-style: italic;
  font-size: 18px;
  font-weight: 800;
  color: #FFFFFF;
  padding: 0px 10px 0px;
  text-align: center;
  text-shadow:
		-1px -1px 0 #000,
		1px -1px 0 #000,
		-1px 1px 0 #000,
		1px 1px 0 #000;

}

.view a.info {
  font-size: 26px;
  text-decoration: none;
  padding: 10px 10px;
  background: #000;
  color: #fff;
  font-family: Raleway, serif;
  text-transform: uppercase;
  box-shadow: 0 0 1px #000;
}

.view a.info:hover {
  box-shadow: 0 0 5px #000
}


/*1*/

.view-first img {
  /*1*/
  transition: all 0.2s linear;
}

.view-first .mask  {
 position: relative;
 display: block;
 opacity: 0;
 background-color: rgba(255,0,4,0.57);
 transition: all 0.4s ease-in-out;
 height: 100%; 
	
}

.view-first h2 {
  transform: translateY(1px);
  opacity: 100;
  transition: all 0.2s ease-in-out;
}

.view-first p {
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.2s linear;
}

.view-first a.info {
  opacity: 0;
  transition: all 0.2s ease-in-out;
}


/* */

.view-first:hover img {
  transform: scale(1.1);
}

.view-first:hover .mask {
	display: block;
  opacity: 1;
}

.view-first:hover h2,
.view-first:hover p,
.view-first:hover a.info {
  opacity: 1;
  transform: translateY(0px);
}

.view-first:hover p {
  transition-delay: 0.1s;
}

.view-first:hover a.info {
  transition-delay: 0.2s;
}
<div class="section group">
	<div class="view view-first">
	<h2>LOGOS</h2>
	<div class="mask">
      <p>The Beginning Part Of The Branding Process.Logos I Have Done For Clients</p>
      <a href="#" class="info">Click Here</a>
    </div>
	</div>

常规 View :

Image on Regular view

问题:

THE ISSUE

期望的结果:

The desired result

最佳答案

问题是 .view-first .mask 类。

对于预期的结果,提到的类需要 POSITION:ABSOLUTE 而不是 RELATIVE。

.view-first .mask  {
 position: absolute;
 display: block;
 opacity: 0;
 background-color: rgba(255,0,4,0.57);
 transition: all 0.4s ease-in-out;
 height: 100%; 
}

这样做会达到预期的效果,但是会出现另一个问题。您将需要调整以下类的 margin-top:

.view-first p

.view a.info

关于html - 背景悬停不出现在标题后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57949179/

相关文章:

jquery - 引导下拉列表的 z-index 或焦点问题

javascript - Bootstrap Dropdown - 移动其他内容

javascript - 具有元素结构概述的预加载器屏幕

html - 避免带有 float 元素网格的空白空间

jquery - 网页的持久标题

html - 如何在菜单的列中显示几个选项

javascript - Safari 中的 html5 视频自动播放延迟

html - 具有相似属性但细微差别的 div 类

html - 为什么文本链接和图标链接不是垂直居中的?

css - 如何使用 Jekyll 在 .md 文件中添加按钮