【发布时间】:2014-11-22 08:42:17
【问题描述】:
我正在尝试设置一个相对于另一个 div 的伪元素,但正如我所注意到的,无法直接设置它,所以我尝试将它添加到 head 的元素中,但如果你不能使用变量做,我需要。
这是我的代码。
var sectionHeight = 0;
$(window).load(function(){
sectionHeight = $('.checkheight').outerHeight(true);
$("#section1::before").css({"height":sectionHeight});
})
这是我第一次拥有的,在我知道我不能通过 jquery 在 css 中设置伪元素的属性之前
这就是我现在拥有的
var sectionHeight = 0;
$(window).load(function(){
sectionHeight = $('.checkheight').outerHeight(true);
})
$('<style>#section1:before{height: sectionHeight }</style>').appendTo('head');
但它不会使用变量来设置高度。
有人知道我的问题的正确解决方案吗?
【问题讨论】:
标签: jquery height pseudo-element