jQuery如何获取innerWidth但没有填充? [英] jQuery how to get innerWidth but without the padding?

查看:77
本文介绍了jQuery如何获取innerWidth但没有填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档中,innerWidth几乎满足了我的需要:

From the docs, innerWidth does almost what I need:


获取内部宽度(不包括边框并包括填充)
是第一个匹配的元素。

"Gets the inner width (excludes the border and includes the padding) for the first matched element."

我需要知道宽度不包括 。即

jquery是否提供类似的功能-做了一些谷歌搜索并且找不到任何解决方案。

Does jquery provide anything like this - done a bit of googling and can't find any solutions.

我考虑过要获取 padding-left padding-right 值以从内部减去宽度-但考虑到这些可能是百分比,像素或em,我不确定这是否可靠。

I thought about getting the padding-left and padding-right values to subtract from inner width- But given these could be percentages, pixels or em I'm not sure if this would be reliable.

有任何建议吗?

推荐答案

您可能只是在寻找width()函数。

You're probably just looking for the width() function..

查看文档,它排除填充: http://api.jquery.com/width/

See the docs, it excludes the padding: http://api.jquery.com/width/

(正如现代浏览器中对CSS width属性的表示所期望的那样)

(Just as intended in modern browser's representation of the css width property)

编辑:现在是2012年jQuery 1.8即将问世。虽然这仍然很重要,但您可能还需要阅读有关jQuery博客的以下文章有关版本1.8中 box-size 注意事项

It's now 2012 and jQuery 1.8 is just coming out. While this is still relevant, you may also want to read the following article from the jQuery blog regarding box-sizing considerations in version 1.8

这篇关于jQuery如何获取innerWidth但没有填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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