css width:calc(100%-100px);替代使用jquery [英] css width: calc(100% -100px); alternative using jquery

查看:1878
本文介绍了css width:calc(100%-100px);替代使用jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 width:calc(100%-100px); 这完成了我需要的工作,唯一的问题是它的兼容性。目前它只能在最新的浏览器,而不是在Safari。

I'd like to use width: calc(100% -100px); which does the job perfectly for what I need it for, the only problem is its compatibility. At the moment it only works in the latest browsers and not at all in Safari.

我可以使用jQuery替代吗?即。获取对象的100%宽度-100px然后动态设置结果作为CSS宽度(所以它会响应)

Could I make an alternative using jQuery? ie. get the 100% width of an object -100px and then dynamically set the result as the CSS width (so it would be responsive)

推荐答案

如果你有一个浏览器不支持 calc 表达式,不难用jQuery模拟:

If you have a browser that doesn't support the calc expression, it's not hard to mimic with jQuery:

$('#yourEl').css('width', '100%').css('width', '-=100px');

让jQuery处理相对计算比自己做的简单得多。

It's much easier to let jQuery handle the relative calculation than doing it yourself.

这篇关于css width:calc(100%-100px);替代使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆