【发布时间】:2021-02-05 01:52:02
【问题描述】:
我在页面底部有一个固定元素,它位于所有其他元素的顶部。它大约是页面宽度的 33%。 当我滚动页面时,其他元素继续在这个元素后面。
我想要的是这个元素的顶部和其他元素开始隐藏的位置之间的一点距离。这很容易实现。 但我的要求是让这个间隙的颜色与该垂直位置的身体颜色相同。
是否可以最好不使用 JavaScript?
这个小提琴中的白色区域是我想要的与身体颜色相同的区域(在那个垂直位置):https://jsfiddle.net/f5qnv8bL/1/
body {
background: -webkit-gradient(linear, left top, left bottom, from(yellow), to(#fffa94)) fixed;
height: 2000px;
}
<div style="background-color:green; float:right; height:750px;">
Something here
</div>
<div style="background-color:white; height: 120px; position:fixed; bottom:0; right:0; width: 400px;">
<div style="background-color:red; height: 100px; position:fixed; bottom:0; right:0; width: 400px;">
</div>
</div>
【问题讨论】:
-
为什么不为两者创建 CSS 类?例如。
.yellow-background { background: -webkit-gradient .....然后body class="yellow-background"以及你的gap div? -
谢谢,这很有效,我应该在发布问题之前尝试一下。但它不适用于我在线性渐变中使用具有不同 alpha 值的相同颜色(而不是使用不同颜色)的某些用例。在某些页面上,还有图像(用作背景)以及叠加在其上的渐变色。请查看我对@coolmatt4321 的回答以及fiddle 的评论。有什么想法让它适用于这些情况吗?
标签: javascript html css padding margin