Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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
Jquery 根据视口高度动态添加顶部填充_Jquery_Css - Fatal编程技术网

Jquery 根据视口高度动态添加顶部填充

Jquery 根据视口高度动态添加顶部填充,jquery,css,Jquery,Css,我试图根据视图端口高度将填充动态设置为“child”div,以便顶部填充为视图端口高度的5% <div id="about-us">Some content <div class="child">Other content</div> </div> 一些内容 其他内容 试试这个: $(document).ready(function() { $('#about-us .child').css('padding-top', $(wind

我试图根据视图端口高度将填充动态设置为“child”div,以便顶部填充为视图端口高度的5%

<div id="about-us">Some content
 <div class="child">Other content</div>
</div>
一些内容
其他内容
试试这个:

$(document).ready(function() {
    $('#about-us .child').css('padding-top', $(window).height() * 0.05);    
});
$(window).height()
将获得视口的高度,将其乘以0.05将获得其5%

尝试以下操作:

$(document).ready(function() {
    $('#about-us .child').css('padding-top', $(window).height() * 0.05);    
});
$(window).height()
将获得视口的高度,将其乘以0.05将获得其5%

尝试以下操作:

$(document).ready(function() {
    $('#about-us .child').css('padding-top', $(window).height() * 0.05);    
});
$(window).height()
将获得视口的高度,将其乘以0.05将获得其5%

尝试以下操作:

$(document).ready(function() {
    $('#about-us .child').css('padding-top', $(window).height() * 0.05);    
});

$(窗口).height()
将得到视口的高度,将其乘以0.05将得到其5%

您可以使用基于视口高度的单位
vh


您可以使用基于视口高度的单位
vh


您可以使用基于视口高度的单位
vh


您可以使用基于视口高度的单位
vh


padding top:5vh
padding top:5vh
padding top:5vh
padding top:5vh