微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – CSS当有宽度时,为什么左边的规则优先于正确的规则?

我有这个CSS代码
#div1{
 height:200px;
 width:200px;
 background-color:red;
 position:absolute;
 right:30px !important; 
 left:0px;
 }

我想问为什么离开:0px;覆盖权:30px!重要而不是相反.或者使用!mportant的那个应该覆盖另一个,这对我来说听起来更合乎逻辑.

正如PaulD.Waite指出的那样,左边和宽度规则更多地覆盖了正确的规则.

所以真正的问题是

当有宽度时,为什么左边优先于右边?

FIDDLE

解决方法

只是为了表明浏览器符合w3c标准:

If the values are over-constrained,ignore the value for ‘left’ (in case the ‘direction’ property of the containing block is ‘rtl’) or ‘right’ (in case ‘direction’ is ‘ltr’) and solve for that value.

所以,如果我们从右到左设置方向

body  {
    direction: rtl;
}

#div1{
    height:200px;
    width:200px;
    background-color:red;
    position:absolute;
    right:30px; 
    left:0px;
}

现在左边被忽略了:

fiddle

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐