我在使用根据屏幕尺寸调整元素大小的 javascript 时遇到了问题。我想将这段具有相同功能的代码翻译成 css 简单类。
$(window).resize(function(){ // On resize
$('item2').css({'height':(($(window).height()))+'px'});
});
我试过了
.test2 {
height: 100%;
}
但不起作用 - 如果我删除脚本部分元素不是所需的(全屏高度)。
脚本的问题在于它实现了标记的样式,除非使用 !important...,否则无法通过媒体查询更改标记
最佳答案
如果 item2
是一个 class
那么您需要在选择器中添加 .
。
$(window).resize(function(){ // On resize
//$('.item2').css({'height':(($(window).height()))+'px'});
$('.item2').height($(window).height());
});
关于Javascript 调整大小函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43513639/