Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用固定定位是否是防止元素触发查看端口上滚动条的唯一方法?_Html_Css - Fatal编程技术网

Html 使用固定定位是否是防止元素触发查看端口上滚动条的唯一方法?

Html 使用固定定位是否是防止元素触发查看端口上滚动条的唯一方法?,html,css,Html,Css,说明: 我有一个页面的内容div将改变高度。当div很小的时候,我想要一个很好的渐变淡入背景色。随着div高度的增加,它应该将渐变进一步向下推,直到脱离页面 这个例子可以正常工作,但是我想知道我是否可以不使用position:fixed on the gradient div来完成这个任务。我不想使用fixed position的原因是,当你上下滚动页面时,上面的例子在iPad上看起来很奇怪。除了渐变外,所有的东西都会移动,所以这会使页面看起来很破碎 是否有任何方法可以在不使用固定定位的情况下

说明:

我有一个页面的内容div将改变高度。当div很小的时候,我想要一个很好的渐变淡入背景色。随着div高度的增加,它应该将渐变进一步向下推,直到脱离页面

这个例子可以正常工作,但是我想知道我是否可以不使用position:fixed on the gradient div来完成这个任务。我不想使用fixed position的原因是,当你上下滚动页面时,上面的例子在iPad上看起来很奇怪。除了渐变外,所有的东西都会移动,所以这会使页面看起来很破碎

是否有任何方法可以在不使用固定定位的情况下构建我的示例?


谢谢

只需调整元素的高度并更改
主体的
溢出
#内容
():


使用jQuery是一种选择吗?如果是这样,这可能是一种解决方案:

每当检测到滚动条时,检查它是由渐变引起的还是由内容部分引起的。如果是因为内容,请保留滚动条;如果不是,请隐藏滚动条

// check to see if there is s scrollbar
if ($("body").height() > $(window).height()) {
    // ok there is a scrollbar, now lets see why there is a scrollbar:
    if ($("#content").height() > $(window).height()){
        // this is legit, do nothing
    }else{
       // the scroll bar is there because of the gradient, hide scroll bar
       $("body").css('overflow','hidden')
    }
})

我不想让尸体溢出来的水被藏起来。当内容溢出正文时,会出现一个滚动条。。。它就在我的例子中。@LuciferSam,是的,它适用于
#content
中的任何内容,就像你的例子一样。如果您还想要其他的东西,请在您的示例中也显示出来。谢谢,我第一眼就忽略了这一点。如果可以的话,我会给你奖金。谢谢,但我真的想知道我是否可以只用HTML和CSS来完成这项工作。
// check to see if there is s scrollbar
if ($("body").height() > $(window).height()) {
    // ok there is a scrollbar, now lets see why there is a scrollbar:
    if ($("#content").height() > $(window).height()){
        // this is legit, do nothing
    }else{
       // the scroll bar is there because of the gradient, hide scroll bar
       $("body").css('overflow','hidden')
    }
})