jQuery.css():Firefox不返回'auto'值 [英] jQuery.css(): Firefox don't return 'auto' values

查看:200
本文介绍了jQuery.css():Firefox不返回'auto'值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将顶部或底部,左侧或右侧的值设置为几个元素。当我试图访问这个值与Firefox(16.0.2),我得到一个错误的值 top (一个特定的值,而不是 auto

I'm setting top or bottom and left or right values to a few elements. When i'm trying to access this values with Firefox (16.0.2), i get a wrong value for top (a specific value instead of auto)

CSS

div {
    bottom:200px;
    left:0px;
    top:auto;
    right:auto;
}

JS

$(function(){
    var top = $('div').css('top');
    alert(top);
});​

您可以在这里尝试:http://jsfiddle.net/UEyxD/2/ (在Chrome / Safari中运作良好)

You can try it here: http://jsfiddle.net/UEyxD/2/ (works well in Chrome/Safari)

任何想法如何防止这种情况?我想获得

Any ideas how to prevent this? I want to get

推荐答案

这是由于浏览器和它如何解释样式,它有点不受控制。但是,对于特定的CSS和jQuery解决方法,您应该能够解决它。例如,如果你不需要绝对定位的项目,你可以删除这个,或更改为 position:static;

This is down to the browser and how it interprets the styles, it is somewhat out of your control. However, with particular CSS and jQuery workarounds you should be able to get around it. For instance, if you do not need to the item to be positioned absolutely then you could remove this, or change it to position:static;

请查看此问题


为什么Chrome和IE会返回不同的值:.css()提供
统一网关到浏览器的计算风格函数,但它
不统一的浏览器实际计算风格的方式。

As to why Chrome and IE return different values: .css() provides a unified gateway to the browsers' computed style functions, but it doesn't unify the way the browsers actually compute the style. It's not uncommon for browsers to decide such edge cases differently.

这篇关于jQuery.css():Firefox不返回'auto'值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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