gpt4 book ai didi

jquery - 使用 jQuery .css() 和 em 更改宽度

转载 作者:行者123 更新时间:2023-12-03 22:39:37 25 4
gpt4 key购买 nike

我需要使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com