Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed css selectors specificity #3475

Closed
wants to merge 2 commits into from
Closed

Fixed css selectors specificity #3475

wants to merge 2 commits into from

Conversation

almaz-khan
Copy link
Contributor

My attempt to fix #1277

@codecov-io
Copy link

codecov-io commented Aug 29, 2019

Codecov Report

Merging #3475 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3475   +/-   ##
=======================================
  Coverage   50.25%   50.25%           
=======================================
  Files           1        1           
  Lines         197      197           
=======================================
  Hits           99       99           
  Misses         98       98

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9f1484...fe05099. Read the comment docs.

@tanhauhau
Copy link
Member

tanhauhau commented Nov 11, 2019

Looking great!

I was wondering, the root cause of the problem is because for some case, all the selectors are not raised by the same amount of specificity:

  div.svelte-xyz div div span.svelte-xyz {  /* <- +2 in class specificity */
    color: red;
    font-size: 2em;
    font-family: 'Comic Sans MS';
  }
  .foo.svelte-xyz {  /* <- +1 in class specificity */
    color: green;
  }

which causes the specificity changed.

so instead of double-up the specificity indiscriminately, a better fix is to make sure all the encapsulated css specificity is raised by the same amount:

  div.svelte-xyz div div span.svelte-xyz {  /* <- +2 in class specificity */
    color: red;
    font-size: 2em;
    font-family: 'Comic Sans MS';
  }
  .foo.svelte-xyz.svelte-xyz {  /* <- +1 in class specificity, add 1 more to match the class specificity */
    color: green;
  }

no need to double up because all of selector specificity are raised by the same amount:

span.svelte-xyz {  /* <- +1 in class specificity */
    color: red;
    font-size: 2em;
    font-family: 'Comic Sans MS';
}
.foo.svelte-xyz {  /* <- +1 in class specificity */
    color: green;
}

@almaz-khan
Copy link
Contributor Author

@tanhauhau thank you for the feedback. Sounds reasonable, will try to implement it

@tanhauhau
Copy link
Member

@almaz-khan how is it? need any help?

@tanhauhau tanhauhau mentioned this pull request Dec 23, 2019
@tanhauhau
Copy link
Member

@almaz-khan thanks for the help, i've opened another PR #4146 for the change

@tanhauhau
Copy link
Member

Fixed in #4146

@tanhauhau tanhauhau closed this Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encapsulated CSS specificity bug
3 participants