【发布时间】:2020-04-28 17:50:14
【问题描述】:
我想使用 jQuery 为 .container 元素设置负数“padding-top”。
padding-top 的值将是 .header 元素和 .navigation 元素的总和。
我尝试了下面的代码,但没有成功。
//This don't work
const $headerHeight = $('.header').height();
const $navHeight = $('.nav').height();
$('.container').css('padding-top', -($headerHeight + $navHeight) + 'px');
它在不是负值时有效。
它将 style="padding-top: xxxpx" 添加到 .container 中,如下所示
div class="container" style="padding-top: xxxpx"
//This works
const $headerHeight = $('.header').height();
const $navHeight = $('.nav').height();
$('.container').css('padding-top', ($headerHeight + $navHeight) + 'px');
我想知道“负值”的情况下怎么写。
【问题讨论】:
标签: javascript jquery