CSS 如何在位置:绝对时删除 Left 属性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10245729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 03:39:49  来源:igfitidea点击:

How to remove Left property when position: absolute?

csscss-position

提问by eric.itzhak

I'm overriding the site CSS to an RTL version when specific language is chosen.

选择特定语言时,我将站点 CSS 覆盖为 RTL 版本。

I have an element which has to have absolute positioning. In the LTR version, I do left: 0px;and it's aligned to the left; in the RTL version I want to do the opposite with right, but the leftproperty isn't overridden so it still stays to the left.

我有一个必须具有绝对定位的元素。在 LTR 版本中,我这样做left: 0px;并且它与左侧对齐;在 RTL 版本中,我想用 做相反的事情right,但该left属性没有被覆盖,所以它仍然留在左边。

  • I've tried hacking with !important, but that didn't work.
  • I've tried setting left: none, but that didn't work.
  • 我试过用 hack !important,但没有用。
  • 我试过设置left: none,但没有奏效。

How can I either set it to none or remove it completely while overriding?

如何在覆盖时将其设置为无或将其完全删除?

回答by Curt

left:auto;

This will default the leftback to the browser default.

这将默认left返回到浏览器默认值。



So if you have your Markup/CSS as:

因此,如果您将标记/CSS 设置为:

<div class="myClass"></div>

.myClass
{
  position:absolute;
  left:0;
}

When setting RTL, you could change to:

设置 RTL 时,您可以更改为:

<div class="myClass rtl"></div>

.myClass
{
  position:absolute;
  left:0;
}
.myClass.rtl
{
  left:auto;
  right:0;
}

回答by Jonas ?ppelgran

In the future one would use left: unset;for unsetting the value of left.

将来会left: unset;用于取消设置 left 的值。

As of today 4 nov 2014 unsetis only supported in Firefox.

截至今天,2014 年 11 月 4 日unset仅在 Firefox 中受支持。

Read more about unset in MDN.

在 MDN 中阅读有关未设置的更多信息。

My guess is we'll be able to use it around year 2022 when IE 11 is properly phased out.

我的猜测是,我们将能够在 2022 年左右 IE 11 正确淘汰时使用它。

回答by MORHERO

left: initial

This will also set leftback to the browser default.

这也将设置left回浏览器默认值。

But important to know property: initialis not supported in IE.

但重要的是要知道property: initialIE 不支持。