1

考虑一下:

.foo {
           position:absolute;
           left:25px;
           top:10px;
           width:130px;
           height:55px;
        }

然后这个:

.change2 .foo {
           left:45px;
           top:90px;  
        }

这种变化就像一种魅力。但是,当更改为此时(基本上从左到右切换):

.change1 .foo {
           right:15px;
           top:90px;
        }

它不起作用。问题是为什么。全部来源:

<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>

    <title>error example</title>
    <style>
        .Body { 
            position:relative;
            padding:0;
            margin:0;
            height:400px;
            width:400px;
            border:1px dashed black;
            font-size:14px;
        }

        .foo {
           position:absolute;
           left:25px;
           top:10px;
           width:130px;
           height:55px;
        }

        .change1 .foo {
           right:15px;
           top:90px;
        }

        .change2 .foo {
           left:45px;
           top:90px;  
        }
    </style>
</head>

<body>
  <div class="Body change1">
    <div class="foo">asdsdada</div> 

    </div>
</body>
</html>
4

3 回答 3

2
.foo {
    position:absolute;
    left:25px;  // already specified 
    top:10px;
    width:130px;
    height:55px;
}

冲突

.change1 .foo {
    right:15px;
    top:90px;
    left: auto;  // reset it
}
于 2013-08-02T08:49:58.497 回答
1

您仍然需要设置 left 属性。通过设置 right,您不会覆盖左侧,除非您明确设置左侧,例如 to autoor inherit。如果一个元素同时具有 left 和 right ,则将使用 left ,除非您将 left 设置为autoor inherit

演示

.change1 .foo {
   right:15px;
   left:auto;
   top:90px;
}
于 2013-08-02T08:50:19.573 回答
0
.change1 .foo {
left: auto;
right:15px;
top:90px;
}
于 2013-09-05T12:28:10.907 回答