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

Add new information about recent CSS inheritance changes with CSS selection and highlight pseudo-classes #38989

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dbarabashh
Copy link
Contributor

@dbarabashh dbarabashh commented Apr 5, 2025

Fix #36458

@dbarabashh dbarabashh requested a review from a team as a code owner April 5, 2025 14:08
@dbarabashh dbarabashh requested review from chrisdavidmills and removed request for a team April 5, 2025 14:08
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/s [PR only] 6-50 LoC changed labels Apr 5, 2025
Copy link
Contributor

github-actions bot commented Apr 5, 2025

Preview URLs

(comment last updated: 2025-04-08 15:12:08)

@Josh-Cena Josh-Cena requested a review from captainbrosset April 5, 2025 15:38
Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbarabashh thanks for the contribution! I've added some thoughts on how I think this could be handled.

@@ -56,6 +56,14 @@ Color contrast ratio is found by comparing the luminosity of the selected text a
- [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Guides/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background)
- [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html)

## Inheritance Behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick thoughts:

  1. This isn't a standard section we normally include in MDN reference pages. If we did have such a section, it would be better placed under a "Description" section (see https://developer.mozilla.org/en-US/docs/Web/CSS/::picker#description for an example).
  2. These are pseudo-elements, not pseudo-classes (double-colon)
  3. This section isn't really providing any information at all. It gives a very vague idea that some behavior has changed, and then links to the DCC blogpost for the specifics. Generally, on MDN, we provide the information, rather than linking to somewhere else for it.

My suggestion would be to:

  1. Add a section to a more general page, such as https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements, or maybe a small guide underneath the page tree of the module where this behavior is defined (under https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_pseudo-elements#guides, perhaps), to explain the behavior.
  2. Add compat data table entries to all of the affected pseudo-element pages, to explain when the change was made (to https://developer.mozilla.org/en-US/docs/Web/CSS/::selection#browser_compatibility, for example). Link to the section or page added in 1., in the data point descriptions.
  3. Optionally also add a "Description" section to all pseudo-element pages relevant to this behavior, which briefly explains the behavior and links to the section or page added in 1. for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! Really helpful and gives a lot more clarity on how this should be implemented.

I’ll make these changes and let you know as soon as I commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbarabashh you are most welcome. Don't hesitate to ping me if you have any questions.

@dbarabashh
Copy link
Contributor Author

I made some changes and updated the text, but I have a feeling its a bit hard to understand. Considering less experienced developers, this explanation might be too complex. What do you think?

/cc @chrisdavidmills

Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbarabashh It's getting there. A couple more comments for you.

I also wondered if you could link to this section from all the pseudo-element reference pages that follow this inheritance model?


Highlight pseudo-elements, such as {{CSSxref("::selection")}}, {{CSSxref("::target-text")}}, {{CSSxref("::highlight()")}}, {{CSSxref("::spelling-error")}}, and {{CSSxref("::grammar-error")}}, follow a consistent inheritance model that differs somewhat from regular element inheritance.

Styles applied to highlight pseudo-elements inherit from their parent elements. This means that if you apply a style to a parent element and then to the highlight pseudo-element of its child, the latter will inherit from both its parent element and the highlight pseudo-element styles of its parent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding it hard to understand the inheritance model as described. Maybe it would be clearer if you added a quick code example to explain what you mean. You could show the live rendered result using the EmedLiveSample macro; see https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Page_structures/Live_samples for an explanation.


Styles applied to highlight pseudo-elements inherit from their parent elements. This means that if you apply a style to a parent element and then to the highlight pseudo-element of its child, the latter will inherit from both its parent element and the highlight pseudo-element styles of its parent.

For detailed information and examples of how this inheritance model works in practice, refer to the [CSS Custom Highlight API](/en-US/docs/Web/API/CSS_Custom_Highlight_API) documentation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the API landing page, I can't see any explanation of the inheritance model. Is it in a particular subpage?

BTW, you could always link to the Chrome page that you linked to previously for the detailed explanation if it is not already on MDN. We just need some information on MDN as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new information about recent CSS inheritance changes with CSS selection and highlight pseudo-classes
2 participants