Skip to content

getComputedStyle() ignores specificity priority #3318

@danon

Description

@danon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    csshas to-upstream testThis bug has a failing to-upstream web platform test waiting to be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions