简体   繁体   English

jQuery CSS的位置没有用

[英]jQuery CSS position right not working

I have an a div with position:absolute . 我有一个position:absolute的div position:absolute I'm trying to position it to right using jQuery but it's not working. 我正试图使用​​jQuery将其定位到正确但它不起作用。 In the code below i'm basically removing left and adding right:0. 在下面的代码中我基本上删除左并添加右:0。 This should position the div to far right. 这应该将div定位在最右边。 using firebug, i can see the inline style being changed to right:0 but nothing is happening. 使用firebug,我可以看到内联样式被改为right:0但没有发生任何事情。 What am i doing wrong. 我究竟做错了什么。 Check http://jsfiddle.net/SJP3b/1/ 查看http://jsfiddle.net/SJP3b/1/

$('div').css({
    left: '',
    right: 0
});

Use left:'auto' that works for me: 使用left:'auto'对我有用:

http://jsfiddle.net/SJP3b/2/ http://jsfiddle.net/SJP3b/2/

Many values can't be set to blank. 许多值不能设置为空白。 So you have to set them to their default css value. 所以你必须将它们设置为默认的css值。

That's auto for the left attribute: 这是left属性的auto

http://www.w3schools.com/css/pr_pos_left.asp http://www.w3schools.com/css/pr_pos_left.asp

you have to use '0px' 你必须使用'0px'

$('div').css({
    left: '',
    right: '0px'
});

EDIT 1: 编辑1:

Sorry, For position:absolute property you can use left and top property. 对不起,对于position:absolute property,你可以使用lefttop属性。 it not about jquery. 它不是关于jquery。

I don't know if right is a valid css key. 我不知道对是否是有效的css密钥。 if it is 如果是

$('div').css({
    left: auto,
    right: 0
});

Should work... 应该管用...

You can also check float:right 你也可以查看float:right

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

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