【发布时间】:2018-06-29 05:40:05
【问题描述】:
我一直在尝试将我的网站转换为 flexbox,但遇到了障碍。一个元素我可以使用浮动来完成,但现在我不能,因为浮动在使用 flexbox 时不起作用。
基本上,当您将鼠标悬停在其上时,我的图像上会弹出一些东西。这是我的工作,但背景颜色没有出现在图像上。我试图弄清楚如何让它出现在图像上,我尝试给元素一个非常高的 z-index 和一堆其他的东西,我空手而归。我希望我可以使用 css 背景图像而不是 html 图像,但我无法让它们在 css 中缩放和保持透视(必须保持背景图像的大小,而不是元素内容)
这是我的示例代码:
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.dldoc p {
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-webkit-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.docwrapper {
display: flex;
justify-content: space-between;
max-width: 100%;
height: 100%;
}
.dldoc {
margin: .5em;
display: block;
text-decoration: none;
overflow: hidden;
min-width: 30vw;
height: 55vw;
}
.dldoc p {
height: 30vh;
background: #f0f;
padding: 0 8px;
text-decoration: none;
width: auto;
z-index: 10000;
}
.dldoc strong {
text-transform: uppercase;
font-size: 7vw;
font-weight: bold;
}
.dldoc em,
.dldoc p {
font-size: 4.5vw;
}
.dldoc:hover>p {
margin-top: -40vw;
}
.dlmap {
padding: 0;
height: 150px;
margin-bottom: 1em;
}
.dlmap:hover,
.dlmap:active {
top;
}
.dldoc img {
z-index: 100;
height: 55vw;
}
.dlmap img,
.dldoc img {
width: 100%;
}
.dlmap strong {
position: absolute;
top: 0;
left: 0;
padding: 5px;
color: #bbb;
background: #233;
}
.dlmap a {
text-transform: uppercase;
left: 0;
z-index: 1;
position: absolute;
top: 150;
height: 75px;
padding: 5px;
background: #233;
font-size: 1.5em;
text-decoration: none;
color: #7d1;
width: 100%;
}
.dlmap a:hover {
background: #7d1;
color: #233;
}
<div class="docwrapper">
<a href="#" class="dldoc" id="resumedl"><img src="https://i.imgur.com/eHu2WOp.png" alt="">
<p><strong>download</strong><br>test1<br>PDF<br><br><em>test text</em></p>
</a>
<a href="#" class="dldoc" id="foliodl"><img src="https://i.imgur.com/eHu2WOp.png" alt="">
<p><strong>download</strong><br>test2<br>ZIP<br><br><em>test text</em></p>
</a>
</div>
【问题讨论】:
-
这其实是一个常见的overlay问题,之前也有人问过。关键是在叠加层上使用绝对定位,在父级上使用相对定位。
-
> 这其实是一个常见的overlay问题,之前也有人问过。关键是在叠加层上使用绝对定位,在父级上使用相对定位。 – 饥饿之星 修复了它!完全忘记了您必须在父母中放置一个亲戚才能绝对像那样工作。谢谢!
标签: html css image flexbox background-color