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
How to remove Left property when position: absolute?
提问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 left
property 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 left
back 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 unset
is only supported in Firefox.
截至今天,2014 年 11 月 4 日unset
仅在 Firefox 中受支持。
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 left
back to the browser default.
这也将设置left
回浏览器默认值。
But important to know property: initial
is not supported in IE.
但重要的是要知道property: initial
IE 不支持。