我需要使用 jQuery 更改 div 的宽度。
当我使用以下内容时,它有效:
$('#footer').css('width', '100%');
$('#footer').css('width', '-=239');
当我使用它时,它有效:
$('#footer').css('width', '100%');
$('#footer').css('width', '-=239px');
但是当我使用它时它没有做任何事情:
$('#footer').css('width', '100%');
$('#footer').css('width', '-=21em');
有没有办法让 jQuery 与 em
一起工作?或者将 em
计算为 px
并设置一个变量,然后减去该值?
编辑:感谢大家纠正我的拼写和代码!
最佳答案
我试过了,它正在工作,我想你应该检查你的代码,我已经在所有浏览器中检查了它,它工作正常,px和em都工作得很好,你可以使用这个代码,把这个代码放在一个虚拟页面中,你可以看看这个作品
<style>
#footer{
background: black;
height:50px;
}
</style>
<script type="text/javascript">
$(function(){
$('#footer').css('width', '100%');
$('#footer').css('width', '-=210em');
});
</script>
<div id="footer"></div>
关于jquery - 使用 jQuery .css() 和 em 更改宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13582518/