如何通过向下滚动页面使线性渐变保持一致
how to make a linear gradient consistent through scrolling down a page
我有以下 html 页面:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
html,body {
height: 100%;
}
body {
margin: 0;
}
</style>
</head>
<body style="margin: 0 auto;text-align:center;background: linear-gradient(to bottom, #243B55, #141E30);">
<p style="font-family: Montserrat; font-style: normal; font-weight: bold; color: rgba(255, 255, 255, 0.92);font-size: 30px;">Text</p>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
</body>
</html>
我知道我在样式标签中添加的 CSS 负责在您滚动页面时制作线性渐变 'repeated',但是有没有办法制作线性渐变在整个滚动过程中背景保持一致,而不必删除现有的 CSS(我愿意添加 CSS),因为我知道我需要现有的 CSS 来做其他事情?
您需要使要设置背景的元素的高度等于文档的全高
你的想法是对的,你只需要改变
如果 属性 height: 100%;
确实有必要,您可以添加包装器并将其添加到其中。
// from
html,body {
height: 100%;
}
//to
html,body {
height: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<style>
html,body {
height: auto;
}
.wrapper {
height: 100%;
}
body {
margin: 0;
}
</style>
</head>
<body style="margin: 0 auto;text-align:center;background: linear-gradient(to bottom, #243B55, #141E30);">
<div class="wrapper">
<p style="font-family: Montserrat; font-style: normal; font-weight: bold; color: rgba(255, 255, 255, 0.92);font-size: 30px;">Text</p>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
</div>
</body>
</html>
我有以下 html 页面:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
html,body {
height: 100%;
}
body {
margin: 0;
}
</style>
</head>
<body style="margin: 0 auto;text-align:center;background: linear-gradient(to bottom, #243B55, #141E30);">
<p style="font-family: Montserrat; font-style: normal; font-weight: bold; color: rgba(255, 255, 255, 0.92);font-size: 30px;">Text</p>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
</body>
</html>
我知道我在样式标签中添加的 CSS 负责在您滚动页面时制作线性渐变 'repeated',但是有没有办法制作线性渐变在整个滚动过程中背景保持一致,而不必删除现有的 CSS(我愿意添加 CSS),因为我知道我需要现有的 CSS 来做其他事情?
您需要使要设置背景的元素的高度等于文档的全高
你的想法是对的,你只需要改变
如果 属性 height: 100%;
确实有必要,您可以添加包装器并将其添加到其中。
// from
html,body {
height: 100%;
}
//to
html,body {
height: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<style>
html,body {
height: auto;
}
.wrapper {
height: 100%;
}
body {
margin: 0;
}
</style>
</head>
<body style="margin: 0 auto;text-align:center;background: linear-gradient(to bottom, #243B55, #141E30);">
<div class="wrapper">
<p style="font-family: Montserrat; font-style: normal; font-weight: bold; color: rgba(255, 255, 255, 0.92);font-size: 30px;">Text</p>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
</div>
</body>
</html>