[英]Position fixed; left works fine, right doesn't
I have a span
called $mySpan
. 我的
span
为$mySpan
。
Calling 呼唤
$mySpan.css({
position : 'fixed',
left : '50%',
top : '15%',
backgroundColor : 'red',
'z-index' : 1000
});
works just fine. 效果很好。 However,
然而,
$mySpan.css({
position : 'fixed',
right : '50%',
top : '15%',
backgroundColor : 'red',
'z-index' : 1000
});
doesn't show the span. 不显示跨度。
As you can see, it's probably not a z-index
problem. 如您所见,这可能不是
z-index
问题。 I'm really confused because my code is quite complex and I haven't been able to build a simple example using jsFiddle. 我真的很困惑,因为我的代码非常复杂,而且我无法使用jsFiddle构建一个简单的示例。 I have no clue where to start looking for what is going wrong.
我不知道从哪里开始寻找问题所在。
Does anyone have a hint as to why the second approach is not working? 是否有人暗示为什么第二种方法不起作用? How could I debug such a problem?
我该如何调试这样的问题?
Try this: 尝试这个:
$mySpan.css({
'position' : 'fixed',
'left' : 'auto', /* <-- oftentimes, browsers screw up if 'left' is still set */
'right' : '50%',
'top' : '15%',
'backgroundColor' : 'red',
'z-index' : 1000
});
The unexpected result can be caused by a margin-right
CSS property. 意外结果可能是由
margin-right
CSS属性引起的。 If this property is set, remove it to fix your code. 如果设置了此属性,请将其删除以修复您的代码。
在第二个例子中,你可能已经错过了$
在$mySpan
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.