【发布时间】:2012-08-27 22:44:37
【问题描述】:
看到这个example。
代码:
alert( "slide-panel2 position: " + $('#slide-panel2').css("left") )
CSS:
#slide-panel2 { left: 0px; }
当实际值设置为0px时,为什么WebKit浏览器会将css left position值提示为auto?
在 Firefox 和 IE 中,它会按预期提示 0px。
已编辑:
正如 Alex 在下面的answer 中所述(我同意他的观点):
因为你的元素有 position: static (默认),所以它会忽略它的布局的 left 属性。如果您的位置属性设置为绝对、相对或固定,浏览器只会关心 left(及其朋友)。
将其更改为 position: relative 会得到预期的结果。
但是根据this reference:
positionCSS 属性的默认值为static而在
static中,top、right、bottom 和 left 属性不适用。
那为什么警报在 Firefox 和 IE 中显示 0px 而在 WebKit 浏览器中显示 auto?
【问题讨论】:
标签: css internet-explorer firefox webkit