考虑一下:
.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>
.foo {
position:absolute;
left:25px; // already specified
top:10px;
width:130px;
height:55px;
}
冲突。
.change1 .foo {
right:15px;
top:90px;
left: auto; // reset it
}
您仍然需要设置left属性。通过设置right,除非显式地将left设置为auto
或inherit
,否则不会覆盖left。如果一个元素同时具有left和right,则将使用left,除非将left设置为auto
或inherit
。
演示
.change1 .foo {
right:15px;
left:auto;
top:90px;
}
.change1 .foo {
left: auto;
right:15px;
top:90px;
}