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

getComputedStyle() ignores specificity priority #3318

Open
danon opened this issue Jan 15, 2022 · 0 comments
Open

getComputedStyle() ignores specificity priority #3318

danon opened this issue Jan 15, 2022 · 0 comments

Comments

@danon
Copy link

danon commented Jan 15, 2022

Basic info:

  • Node.js version: 16.13.0
  • jsdom version: 19.0.0
  1. Use any styles, that depend on specificy
    <style>
     .parent p { color: black; }  // this should take precedense, since it's more specific, according to CSS
     p { color: red; }
    </style>
  2. Use them in HTML

The CSS specificity rules are described: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

Minimal reproduction case

var JSDOM = require("jsdom").JSDOM;

const dom = new JSDOM(`<!DOCTYPE html>
<style>
 div.parent p { color: black; }
 p { color: red; }
</style>

<div class="parent">
    <p>Hi</p>
</div>
`);

const style = dom.window.getComputedStyle(dom.window.document.querySelector("p"));

console.log(style);

How does similar code behave in browsers?

In every browser, getComputedStyle() returns color: black, in JSDOM it's color: red.

image
image
image

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

No branches or pull requests

1 participant