how to override left:0 using CSS or Jquery?

◇◆丶佛笑我妖孽 提交于 2019-12-20 09:23:09

问题


I have an element, which has the following CSS:

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

The element does not span the whole screen. I would like it to "align" to the right hand side of the screen.

This would be easy, if I just removed left: 0, but I cannot tamper with the above CSS, so I need some CSS or Jquery to override, disable or remove the left:0 CSS.

Thanks for help!


回答1:


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.




回答2:


Using CSS:

.elem {
    left: auto;
}

Using JQuery:

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



回答3:


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




回答4:


With jquery:

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



回答5:


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;
  }


来源:https://stackoverflow.com/questions/10102915/how-to-override-left0-using-css-or-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!