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

Correct pseudo class selector #37168

Closed
wants to merge 1 commit into from
Closed

Conversation

andmperotti
Copy link

The original code had the psudo class selector inside the parentheses with the part pseudo element value, which is why the styling was not working when the element was active.

Description

The css code needs to use a psueod class selecor however it was typed in the selector as a value to the 'part' psudo element selector. Thus this change moves 'active' to be a psudo class selector following the part's parentheses and value.

Motivation

I was reading over this resource to learn about the 'part' psudo element selector and was looking at the example and started playing with the code because I thought it wasn't working.

The original code had the psudo class selector inside the parentheses with the part pseudo element value, which is why the styling was not working when the element was active.
@andmperotti andmperotti requested a review from a team as a code owner December 10, 2024 17:20
@andmperotti andmperotti requested review from estelle and removed request for a team December 10, 2024 17:20
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/xs [PR only] 0-5 LoC changed labels Dec 10, 2024
Copy link
Contributor

Preview URLs

@@ -73,7 +73,7 @@ tabbed-custom-element::part(tab):hover {
color: white;
}

tabbed-custom-element::part(tab active) {
tabbed-custom-element::part(tab):active {
Copy link
Member

Choose a reason for hiding this comment

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

The original is correct.

All part names used in ::part() pseudo-element must be present in the part value declared on the shadow tree element but the order of the part names doesn't matter, i.e., the selectors ::part(tab active) and ::part(active tab) are the same.

In the HTML, we have <div part="tab active">Tab A</div>. The ::part(tab active) matches that.

Copy link
Author

@andmperotti andmperotti Dec 10, 2024

Choose a reason for hiding this comment

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

Oh ok I understand now thank you.
I guess I was stuck on what I thought was using the 'active' pseudo class for styling the active div tab the user interacts with, and not just the 'active' part value tab.

And if you wanted the tabs to have a blue bottom border when active, here I changed 'active' part value to 'default' and use the active pseudo class selector.
tabbed-custom-element::part(tab) {
color: blue;
border-bottom: transparent solid 4px;
}

tabbed-custom-element::part(tab):hover {
background-color: black;
color: white;
}

tabbed-custom-element::part(tab default) {
border-color: blue;
}

tabbed-custom-element::part(tab):active {
border-color: blue;
}

Sorry I'm rambling but wanted to get this knot untangled in my brain.

Copy link
Member

Choose a reason for hiding this comment

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

would changing "active" to "hilite" in the HTML and CSS make it less confusing?

@estelle estelle closed this Dec 11, 2024
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/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants