Saddam Alam
Saddam Alam

Reputation: 11

Please Explain: SassScript parent-selector property

I have saw this code in sassscript but it does'nt make my sense and I'm unable to found any official documentation regarding the mention sasscript css output

SassScript

.main aside:hover,
.sidebar p {
  parent-selector: &;
  // => ((unquote(".main") unquote("aside:hover")),
  //     (unquote(".sidebar") unquote("p")))
}

CSS Output

.main aside:hover,
.sidebar p {
  parent-selector: .main aside:hover, .sidebar p;
}

explain how this will work, in css. is this officially documented by w3c or not.

Upvotes: 0

Views: 72

Answers (1)

iorgu
iorgu

Reputation: 3043

In standard CSS, there is no "parent-selector" functionality. CSS primarily deals with selecting and styling elements based on their relationship to other elements, but it doesn't provide a way to select a parent based on the behavior of its children.

So, this won't work:

.main aside:hover,
.sidebar p {
  parent-selector: .main aside:hover, .sidebar p;
}

Well pointed out, indeed, currently it is useless.

In the CSS Selectors Level 4 Working Draft introduced a new pseudo-class called :has(), which allows us to select parent - which is currently not supported in all major browsers.

li:has(> a.active) {
  /* styles to apply to the li tag */
}

In this example, it selects the li element that is a direct parent of the a element with class active.

Upvotes: 0

Related Questions