gpt4 book ai didi

css - 背景渐变 - 无滚动条或重复填充页面

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

我有一个背景渐变,看起来不错,但我有一个问题,在短页面上背景太长并导致不必要的滚动条,在长页面上背景将开始重复而不是拉伸(stretch)以填满整个页面。

这是我使用的 CSS:

html, body{
font-size:1em;
font-family: "ff-dagny-web-pro", Helvetica, Arial, sans-serif;
line-height:1.438em;
color:#222;
margin: 0;
padding: 0;
text-align: justify;
background: rgb(0,0,0); /* Old browsers */
background: -moz-linear-gradient(top, rgba(0,0,0,1) 25%, rgba(209,209,209,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(25%,rgba(0,0,0,1)), color-stop(100%,rgba(209,209,209,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,1) 25%,rgba(209,209,209,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,1) 25%,rgba(209,209,209,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,1) 25%,rgba(209,209,209,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,1) 25%,rgba(209,209,209,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#d1d1d1',GradientType=0 ); /* IE6-9 */

}

当我添加 height: 100%; 时,它会导致短页面出现滚动条。我尝试使用 overflow: hidden; 删除它们,但这导致长页面上的任何内容都无法显示!另外,如果我不使用 height: 100%;,那么渐变只会填充大约一半的页面并重复。

对于该做什么或尝试解决这个问题,我有点困惑。

注意:虽然我更喜欢 CSS 解决方案,但如果有有效的 javascript 解决方案(使用 jQuery),我愿意尝试使用它来实现。

最佳答案

导致此问题的原因是我尝试实现“粘性页脚”。我删除了所有高度要求(即:min-heightheight),浏览器相应地进行了调整,没有问题。

作为旁注,我使用以下代码解决了粘性页脚问题:

$(function() {
var height = $(window).height() - ($("header").outerHeight() + $("footer").outerHeight() );
$("#page-content").css("min-height",height+"px");
});

关于css - 背景渐变 - 无滚动条或重复填充页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12470709/

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