There is currently no way to select the parent of an element in CSS.
If there was a way to do it, it would be in either of the current CSS selectors specs:
That said, the Selectors Level 4 Working Draft includes a :has()
pseudo-class that will provide this capability. It will be similar to the jQuery implementation.
li:has(> a.active) { /* styles to apply to the li tag */ }
However, as of 2021, this is still not supported by any browser.
In the meantime, you’ll have to resort to JavaScript if you need to select a parent element.
Related Posts:
- Nesting CSS classes
- What is the difference between the selectors “.class.class” and “.class .class”?
- In CSS what is the difference between “.” and “#” when declaring a set of styles? [duplicate]
- What does “*” mean in CSS?
- What does an asterisk (*) do in a CSS selector?
- Is there an opposite CSS pseudo-class to :hover?
- Combine :after with :hover
- What does the “~” (tilde/squiggle/twiddle) CSS selector mean?
- Is there a “previous sibling” selector?
- How can I apply styles to multiple classes at once?
- Specify multiple attribute selectors in CSS
- CSS “and” and “or”
- CSS selector for first element with class
- How to select label for=”XYZ” in CSS?
- How to align a to the middle (horizontally/width) of the page [duplicate]
- Animate the overflow property
- Is there a color code for transparent in HTML?
- What does auto do in margin: 0 auto?
- CSS Invalid Property Value?
- css to make bootstrap navbar transparent
- How to word wrap text in HTML?
- border-radius not working
- How to show tags in my tumblr theme?
- HTML span align center not working?
- Adding a blurred border in CSS
- HTML colspan in CSS
- Flexbox float right
- How to exclude particular class name in CSS selector?
- How to make certain text not selectable with CSS
- How do I center an SVG in a div?
- How to expand textarea width to 100% of parent (or how to expand any HTML element to 100% of parent width)?
- Remove Open Sans from Twenty Twelve theme
- Is it possible to enqueue a raw CSS string directly from within a template file?
- Overriding Gallery Margin
- How to dequeue a stylesheet by src, not handle?
- Gutenberg Block Editor Match Admin Styles & Frontend Styles
- wordpress CSS styles – footer border do not show
- The correct way to include JavaScript and CSS in my WordPress Themes
- Styling Custom Meta Boxes?
- get_stylesheet_uri returns wrong path
- Customizing wordpress to match your site theme
- Is it better to put CSS in additional CSS or in Child theme styles.css [closed]
- Adding HTML to the Header, Screws up in IE7
- How To Load Different CSS Style, Based On Language When Using QtranslateX [closed]
- Getting page output HTML without request (for CriticalCSS, PurgeCSS)
- How to organize priority of plugins CSS files?
- Responsive Images Warping
- Remove margin from CSS gradient color code
- Unable to remove space between header and slider section in wordpress website
- Seperate functions.php for part of site
- Internet Explorer ignore my css
- Hover colour spreading out beyond submit button
- Some Text of website page on Iphone Safari become invisible
- Child Theme CSS not showing at all
- post_class not working with css
- Adding CSS to Blog Posts?
- Where do I go to change the position of the style.css?
- Using PHP Increment and Conditional Statement to Alternate Loop Background
- wp_enqueue_media is not loading styles
- Remove a Style Tag from WP Theme
- Simple way to add custom class and ids to individual Gutenberg blocks
- child theme appears again when I put the header with parent name.
- How to Add a Read-only Textbox With Text in it That Has a Button to Copy it?
- cookie free subdomain and @font-face
- How to change the standard navigation menu color when using genesis [closed]
- How to add class to an html output element in tinyMCE paragraph drop down menu
- Why doesn’t WP recognize images in posts like other content? [closed]
- CSS isn’t rendered on a post but just posted as text [closed]
- How would I create the same popup in css and javascript as the one in contact button on the site https://www.sublimotionibiza.com/es/main.html [closed]
- Customizing the Post/Page Editor in Classic Editor
- How to use css only H2 Tag? Site is considering website title also H2 tag and changing its style as well
- How to edit CSS style sheet after migrating from local
- WordPress footer always at the bottom of the screen-page
- Dequeing Parent Fontawesome Deques Parent Styles
- Border around menu button [closed]
- Correct use of !important
- How to change hover link colour for blog post (body) text only
- Problems styling a Custom Link in a Menu
- Font .woff files loaded don’t correspond to the displayed styles [closed]
- CSS transition from 0px width to 100% width
- Custom CSS rule overridden in theme
- Twenty Fourteen: Shrinking header while scrolling down
- Style sidebar for a custom page template exclusively
- CSS ?ver=4.7.3 not found
- Custom CSS rules only apply to home page
- Sticky Button not working WP. But does it JS Fiddle
- How to enqueue google fonts if we use directly in style.css
- Trouble with adding preloader to my home page index.html and index.js
- How to change in css with a custom theme?
- Wesbite super slow on iphone / very fast on desktop with same connection on wifi
- How can a left and right margin be added to the admin bar without access to “…wp-includes/admin-bar.php”?
- Inserting a DIV Block Into a Listing of Excerpts?
- WordPress Custom Superfish CSS Problem [closed]
- Browser stacks different versions of style.css
- Is it possible to make invisible a div only on certain pages using CSS?
- What CSS selectors to know for WordPress? [closed]
- MY CSS FILE IS MISBEHAVING. IS NOT WORKING WELL ON MY WP SITE [closed]
- Remove / Disable default custom.css?ver=1.0.0
- Website is not showing updated CSS
- How to hide button with CSS class?