jonkemp/inline-css

Selector specificity not working for !important rules

開放

#32 建立於 2016年3月14日

 (8 則留言) (0 個反應) (0 位負責人)JavaScript (78 個分叉)github user discovery
enhancementhelp wanted

倉庫指標

星標
 (438 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

When two selectors match the same element, and both have !important, then the selector specificity is ignored and the last rule wins:

inlineCss('<style>p a {color: red!important} a{color: black!important}</style>  <p><a>test', {url: '/'}).then(s=>console.log(s))
// '<p><a style="color: black;">test</a></p>'
inlineCss('<style>a{color: black!important} p a {color: red!important}</style>  <p><a>test', {url: '/'}).then(s=>console.log(s))
// '<p><a style="color: red;">test</a></p>'

However for the browsers it’s different. No matter which rule goes first, if both have !important in them, the more specific wins.

貢獻者指南