How to select parent pseudo-class from within child using scss
So seems like this is really easy. Whoops.
You just do the following:
SCSS:
.child {
.parent:first-child & {
height: 50px;
}
}
This probably looks silly, but for my situation, it's actually useful.
Simplified SASS selectors for child pseudo elements?
You can use &
again:
.reveal-div {
border: 2px solid black;
// I toggle the all-borders-hidden class on the parent/ancestor
// reveal-div class element
// The following works, but it's a bit verbose - can it be simplified
&.all-borders-hidden {
border: none;
* {
border: none;
}
&::after{
border: none;
}
&::before{
border: none;
}
}
}
and if they are sharing the border:none
you can do this:
.reveal-div {
border: 2px solid black;
// I toggle the all-borders-hidden class on the parent/ancestor
// reveal-div class element
// The following works, but it's a bit verbose - can it be simplified
&.all-borders-hidden {
&,
*,
&::before,
&::after{
border: none;
}
}
}
Is there a CSS parent selector?
The Selectors Level 4 Working Draft includes a :has()
pseudo-class that will provide this capability. It will be similar to the jQuery implementation, but is currently not supported by Firefox.
li:has(> a.active) { /* styles to apply to the li tag */ }
As of 2022, Firefox is the only browser not supporting it by default.
In the meantime, you'll have to resort to JavaScript in Firefox if you need to select a parent element with full cross-browser support.
Change css of child on parent's pseudo-element (::after/::before) hover with CSS
pointer-events
can help you here
#child {
color: white;
}
#parent *,
#parent{
pointer-events: none; /* disable for parent and all childs */
}
#parent::after {
content: "This";
color: black;
pointer-events: initial; /* keep it for the pseudo element */
}
#parent:hover #child { /* the pseudo element will trigger this hover */
color: black;
}
<div id='parent'>
<span>Change child color when you hover</span>
<div id='child'>
Color
</div>
</div>
Related Topics
<Style> and <Script> Tags Are Displayed Physically on Page
How to Specify a Div's Position as Absolute and Relative at The Same Time
How to Loop a CSS Animation with Multiple Keyframe Definitions
Material-Ui-Next: Setting Image Size to Fit a Container
CSS Grid: Grid-Row Not Working in Chrome Browser
Font-Awesome Class with Multiple Different Icons
Background Color Not Showing for a Div
How to Reverse-Engineer a Webkit Matrix3D Transform
How to Enable SASS Line Numbers in CSS Output
Creating Small Navbar and a Side Panel in Materialize CSS
Sass Loop Through Array and Present Variable
How to Have a Progress Bar Move from Right to Left Based on a Negative Value in Twitter Bootstrap
Polymer Chip-To-Card Pattern with Core-Animated-Pages and a Long List
How to Make a Horizontally Scrollable Cell in a Datatable
Borderradius Style Property Not Rounding The Edges in Reactjs