Skip to content

Instantly share code, notes, and snippets.

@otakupahp
Last active March 10, 2023 20:10
Show Gist options
  • Save otakupahp/2d73693ddfbe67cd848c50e09d7c198a to your computer and use it in GitHub Desktop.
Save otakupahp/2d73693ddfbe67cd848c50e09d7c198a to your computer and use it in GitHub Desktop.
Add a new class on an specific position
// Desired output
// .woocommerce-page.single-product main .product_cat-intentional-pause form.cart #wc-stripe-payment-request-wrapper
.woocommerce-page.single-product {
main {
form.cart {
#wc-stripe-payment-request-wrapper {
$selector: nth(&,1); // Current element
$grandparent: nth($selector, -2); // Grandparent selector
$grandparent-pos: index($selector, $grandparent);
$new-grandparent: set-nth($selector, $grandparent-pos, '.extra-class form.cart');
@at-root #{$new-grandparent} {
color: red;
}
}
}
}
}
.woocommerce-page.single-product main .product_cat-intentional-pause form.cart #wc-stripe-payment-request-wrapper {
color: red;
}
{
"sass": {
"compiler": "dart-sass/1.32.12",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment