/    Sign up×
Articles /Pin to ProfileBookmark

The CSS Parent Selector we’ve been waiting for

As browser support for the :has() selector grows, front-end devs will finally have a CSS-only approach for parent selectors. For example, let’s say you have a paragraph with the class .child and you want to style the parent DIV:

This basic example will apply a 2px black border around the parent DIV. Keep in mind, full support is not quite there yet in all major browsers so use this trick cautiously.

Sign-up at Design.dev for more tips

This quick tip was originally created for subscribers to the design.dev newsletter. Subscribe today to get additional content like this, as well as a set of 300 custom icons. 🙌



Help @designdev 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 2.27,
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: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,

tipper: @neststayhome,
tipped: article
amount: 1000 SATS,