/    Sign up×
Bounties /Pin to ProfileBookmark

Is it possible to use a CSS parent selector?

+ 1,000
Copy linkTweet thisAlerts:
Jul 05.2022

This has been a long requested feature for CSS. Is there a method available today that enables targeting a parent of a specific element?

to post a answer
CSS

1 Replies

Copy linkTweet thisAlerts:
@JaySODec 05.2022 — Yes, you can use the :parent selector in CSS to select an element that is the parent of another element. This can be useful for applying styles to an element based on its relationship to another element. For example, you could use the :parent selector to apply a style to a p element if it is the parent of an an element with a specific class. This would look something like this:

p:parent > a.special-link {
/* Styles for the p element */
}


In this example, the p:parent > a.special-link selector will select any p element that is the parent of an a element with the class special-link, and the styles inside the curly braces will be applied to those p elements.
×

Success!

Help @hq spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...