繁体   English   中英

位置固定; 左边工作正常,右边不行

[英]Position fixed; left works fine, right doesn't

我的span$mySpan

呼唤

$mySpan.css({
    position        : 'fixed',
    left            : '50%',
    top             : '15%',
    backgroundColor : 'red',
    'z-index'       : 1000
});

效果很好。 然而,

$mySpan.css({
    position        : 'fixed',
    right           : '50%',
    top             : '15%',
    backgroundColor : 'red',
    'z-index'       : 1000
});

不显示跨度。

如您所见,这可能不是z-index问题。 我真的很困惑,因为我的代码非常复杂,而且我无法使用jsFiddle构建一个简单的示例。 我不知道从哪里开始寻找问题所在。

是否有人暗示为什么第二种方法不起作用? 我该如何调试这样的问题?

尝试这个:

$mySpan.css({
    'position'        : 'fixed',
    'left'            : 'auto', /* <-- oftentimes, browsers screw up if 'left' is still set */
    'right'           : '50%',
    'top'             : '15%',
    'backgroundColor' : 'red',
    'z-index'         : 1000
});

意外结果可能是由margin-right CSS属性引起的。 如果设置了此属性,请将其删除以修复您的代码。

在第二个例子中,你可能已经错过了$$mySpan

暂无
暂无

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

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