我想在div列元素中显示一些内容(一个图标和一些标题文本)。当我将鼠标悬停在文本上时,我试图通过在旧内容上过渡一个框来隐藏内容,然后在新颜色上方显示更多信息
我当前正在使用:before psuedo元素转换新的背景色,该背景色最初是0不透明度,然后向上过渡并变为完全不透明度。我似乎无法让我的孩子div再出现在顶部。
.feature {
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 5%;
text-align: center;
box-sizing: border-box;
}
.feature h2 {
font-size: 1.5em;
color: #006699;
margin-top: 0;
margin-bottom: 0.5em;
}
.feature a {
text-decoration: none;
}
.feature .icon {
font-size: 3em;
color: #575757;
}
.feature:before {
content: "";
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 0;
background-color: #003366;
transition: all 0.33s ease;
z-index: 10;
}
.feature .details {
display: none;
z-index: 15;
}
.feature:hover:before {
height: 100%;
opacity: 1;
box-shadow: inset 0px 0px 2px 2px rgba(75, 179, 219, 0.75);
z-index: 10;
}
.features:hover .details {
display: block;
color: #fff;
}
<div class="feature h_medium bg-gray radius-2">
<div class="icon mb-15">
<i class="fas fa-people-carry"></i>
</div>
<h2>Main Title</h2>
<div class="details">
<h2>Main Title (again)</h2>
<p>Some level of content that describes the title</p>
</div>
</div>
Id希望悬停鼠标首先填充feature元素上的蓝色框封面-然后我希望details div填充蓝色框上的
答案 0 :(得分:3)
这是我为您提供的解决方案。希望它能满足您的要求。我只是在以下块中进行了一些更改。如果您遇到任何问题,请随时告知。
.feature .details {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display:block;
opacity: 0;
z-index: 15;
}
.feature:hover .details {
opacity: 1;
transition: all 0.33s ease .2s;
}
.feature {
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 5%;
text-align: center;
box-sizing: border-box;
}
.feature h2 {
font-size: 1.5em;
color: #006699;
margin-top: 0;
margin-bottom: 0.5em;
}
.feature a {
text-decoration: none;
}
.feature .icon {
font-size: 3em;
color: #575757;
}
.feature:before {
content: "";
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 0;
background-color: #003366;
transition: all 0.33s ease;
z-index: 10;
}
.feature .details {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display:block;
opacity: 0;
z-index: 15;
}
.feature:hover:before {
height: 100%;
opacity: 1;
box-shadow: inset 0px 0px 2px 2px rgba(75,179,219,0.75);
z-index: 10;
}
.feature:hover .details {
opacity: 1;
transition: all 0.33s ease .2s;
}
<div class="feature h_medium bg-gray radius-2">
<div class="icon mb-15">
<i class="fas fa-people-carry"></i>
</div>
<h2>Main Title</h2>
<div class="details">
<h2>Main Title (again)</h2>
<p>Some level of content that describes the title</p>
</div>
</div>