如何使用 CSS 或 Jquery 覆盖左: 0?

我有一个元素,它具有以下 CSS:

.elem {
left: 0;
position: fixed;
right: 0;
width: 60%;
z-index: 1000;
}

元素不会跨越整个屏幕。我希望它“对齐”到屏幕的右手边。

这将是很容易的,如果我只是删除了 左: 0,但我不能篡改上述 CSS,所以我需要一些 CSS 或 Jquery 来覆盖,禁用或删除的 左: 0 CSS。

谢谢帮忙!

69799 次浏览

The default value for left is auto, so just set it to that and you will "reset" it.

.elem {
left: auto;
}

Make sure that the above comes after the original CSS file.

Try auto property in CSS, which is equal to the default value.

With jquery:

$(".elem").css("left", "");

Whether this style you extracted is an external or an internal one, you can override it with an internal one such as:

.elem {
position: fixed;
right: 0;
width: 60%;
z-index: 1000;
}

Using CSS:

.elem {
left: auto;
}

Using JQuery:

$(".elem").css("left", "auto");