Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular + SCSS: how to apply style on component on parent :hover

I am trying to show my component when it's parent is hovered.

The action-list component will display a list of possible actions when an element is hovered. The goal is to have a kind of contextual actions.

I am using host-context to detect the when a parent is hovered, but the issue is that will go through the parent tree. If I'm have the following : :host-context(:hover) {...} the action-listwill be shown as soon any of its ancestor (until body)are hover. In that case it will always be displayed Demo

I managed to make it work by setting a css class on the parent and in scss :host-context(.parent:hover) {...}` Demo

It is working well, but I'd like to avoid having to set an extra class on the parent.

QUESTION:

I know it is not possible in pure CSS, but is there an angular/scss magic syntax that will allow to select the direct parent?

Something like :host-context(parent():hover) {...}

like image 583
Mikado68 Avatar asked Oct 23 '25 09:10

Mikado68


1 Answers

Here is two solutions :

  • In the parent component :
.parent-component:hover ::ng-deep app-child-component .div-in-child {}
  • In the children component
:host-context(app-parent-component:hover) .child-component-div {}

::ng-deep let you to force a style down through the child component tree into all the child component views.

like image 56
Martin Paucot Avatar answered Oct 26 '25 02:10

Martin Paucot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!