简体   繁体   English

定义最大宽度时,在野生动物园中获取实际的表宽度

[英]Get real table width in safari when max-width is defined

I am using bootstrap and it gives .table elements the following styles: 我正在使用引导程序,它为.table元素提供以下样式:

width:100%;
max-width:100%;

If I put that table into a container which is not wide enough to fit the table's contents, the table will ignore its max width and render wider than the container. 如果我将该表放入一个宽度不足以容纳表内容的容器中,则该表将忽略其最大宽度,并使其比容器宽。

The problem is that safari does not report the width of that table correctly . 问题是, Safari无法正确报告该表的宽度 It reports it as if it were 100% of the container. 它报告它好像是容器的100%。

Open this on chrome and then on safari: http://jsfiddle.net/6nfotj8j/2/ 在chrome上然后在safari上打开它: http : //jsfiddle.net/6nfotj8j/2/

How can I get jquery to give me the correct width of the table without removing the max-width ? 如何在删除max-width 情况下让jquery给我正确的表max-width

(side note - this code will go into a jquery plugin, so id like to change/assume as little as possible about the underlying DOM) (旁注-此代码将放入jquery插件中,因此id希望尽可能少地更改/假定有关底层DOM的信息)

edit 编辑
only affects safari version 7, works as expected in 5 仅影响Safari版本7,按预期在5中运行

野生动物园报告宽度为48!

Using the inspector in safari you can see its actually ~523px (borders added) and your fiddles prints ~522px which is fine (borders not calculated - change to outerWidth() to include borders + padding + margin). 在野生动物园中使用检查器,您实际上可以看到它的〜523px(添加了边界),并且您的小提琴可以打印〜522px,这很好(未计算边界-更改为outerWidth()以包括边框+填充+边距)。

In Chrome - script outputs ~516px and inspector ~518px, again that's correct (borders missing again). 在Chrome中-脚本输出〜516px,检查器输出〜518px,再次正确(边界再次丢失)。

The difference is between how the table renders in the two different browsers - fonts, line-breaks etc... 区别在于表格在两种不同浏览器中的呈现方式-字体,换行符等...

No problem here (tested also in FF, IE), you are getting the correct actual width of the table. 没问题(在FF,IE中也经过测试),您将获得正确的表格实际宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM