gpt4 book ai didi

html - 占用父元素高度 100% 的 CSS 覆盖

转载 作者:行者123 更新时间:2023-11-28 08:51:25 24 4
gpt4 key购买 nike

我需要将片段中的元素着色得更深。为此,我有一个部分透明的黑色覆盖元素。我希望它能够完整地覆盖红色元素。问题是,我无法将叠加层设置为 100% 高度。为什么这行不通,如何在不指定确切高度的情况下让它工作?

.overlay-shell {
position: relative;
top: 0;
left: 0;
}

.overlay {
background-color: rgba(0, 0, 0, 0.5);
top: 0;
left: 0;
height: 60px; /* how do I get this to take 100% of the height? */
width: 100%;
position: absolute;
}

ul.alarms {
list-style: none;
margin: 0 30px;
}

ul.alarms li.alarm {
background-size: 100%;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #c53635), color-stop(50%, #9d2b2a), color-stop(51%, #952928), color-stop(100%, #9d2b2a));
background-image: -moz-linear-gradient(#c53635 0%, #9d2b2a 50%, #952928 51%, #9d2b2a 100%);
background-image: -webkit-linear-gradient(#c53635 0%, #9d2b2a 50%, #952928 51%, #9d2b2a 100%);
background-image: linear-gradient(#c53635 0%, #9d2b2a 50%, #952928 51%, #9d2b2a 100%);
}

ul.alarms .content {

}

ul.alarms li .right-sidebar {
float: right;
max-width: 180px;
}

ul.alarms .bottom-bar {
clear: both;
}

.response-btn {
display: inline-block;
width: 20%;
text-align: center;
margin: 0px;
padding: 0px;
}
<html>
<ul class="alarms">
<li class="alarm" id="alert_87590">
<div class="overlay-shell">
<div class="overlay"></div>
</div>
<div class="content">
<div class="primary">
<a href="/senior/1828"><h1 class="provisioned-service-name">Hannah Montana</h1>
</a>
</div>
</div>
<div class="right-sidebar">
<p>
<a class="address" href="/senior/1828">Unit 128</a>
</p>
</div>
<div class="bottom-bar">
<div class="response-btn">
<span>Yes</span>
</div><div class="response-btn">
<span>OK</span>
</div><div class="response-btn">
<span>Thank you</span>
</div><div class="response-btn">
<span>Custom</span>
</div><div class="response-btn">
<span>Roger</span>
</div>
</div>
</li>
</ul>

</html>

最佳答案

将 .overlay 的高度设置为 100vh,即等于视口(viewport)高度:

overlay {
background-color: rgba(0, 0, 0, 0.5);
top: 0;
left: 0;
height: 100vh;
width: 100%;
position: absolute;
}

你仍然会得到整个页面高度的黑色覆盖层

关于html - 占用父元素高度 100% 的 CSS 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27323794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com