choosing every single potential direct descendant of ng-content

Latest Update:

After utilizing ::ng-deep, some progress was made.

:host {
&::ng-deep*:hover {
    background: red;
  }
}

This method applies the hover effect to individual items instead of the whole container. However, it also affects all children and grandchildren of the item.

I experimented with using :first-child instead of *, but it seems like ::ng-deep is required to reach this level of depth.


The goal is to create a template that styles all included children.

@Component({
  selector: 'custom-template',
  template: '<ng-content></ng-content>',
  styles: [`
    :host {
      display: flex;
      flex-direction: column;
    }
  `]
})
export class Template {
}

Currently, the template functions correctly by styling the content within it.

The issue arises when trying to style the content itself which does not reflect any changes:

style.scss:

:host {
  display: flex; 
  flex-direction: column; 
  * {
    &:hover { 
      background: red; 
    }
  }
}

In my case, an array of items is being passed:

<custom-template>
  <div *ngFor="let item of items">
</custom-template>

My objective is to add hover behavior to any child elements passed into the template.

LATEST UPDATE:

Previous attempts:

:host {
  &*:hover {
    background: red; 
  }
}

Answer №1

Feel free to give this a try, it's expected to function correctly.

:host:hover { background: red;}
 or
:host(:hover) { background: red;}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to align a bootstrap 4 row both vertically and horizontally in the center amidst other rows

Assume there is a main menu followed by three rows. The first row should be at the top and the third at the bottom, while the second row needs to be centered both vertically and horizontally. As you scroll down, the main menu should be able to hide while ...

Sass - Retain the original class hierarchy

Apologies for the vague title, I couldn't think of a better one. As I compile my scss, this piece of code: .foo { ... &__bar { ... } } transforms into the expected output below: .foo { ... } .foo__bar { ... } However, I actually need it t ...

Angular 4: Transform a string into an array containing multiple objects

Recently, I received an API response that looks like this: { "status": "success", "code": 0, "message": "version list", "payload" : "[{\"code\":\"AB\",\"short\":\"AB\",\"name\":\"Alberta&b ...

The leaflet map I created is not showing up on my website for some reason

I am currently working on a project using ReactJS and NextJS. One issue I am facing is that my leaflet map is not filling the entire parent div on my page, and it is not showing up at all. I had expected the map to automatically adjust to the parent div s ...

I encountered a warning while running the npm command. Can someone provide guidance on how to address this issue?

npm WARNING config key key and cert are no longer utilized for most registry functions. npm WARNING config Use registry scoped keyfile and certfile instead. npm WARNING config Example: npm WARNING config //another-registry.tld/:keyfile=/path/to/key ...

Move the remaining blocks after deletion

Is there a way to create a seamless effect when removing an element? I am looking to incorporate a transition or slide effect when deleting a block and causing the blocks below it to move up smoothly. const animateCSS = (element, animation, prefix = &ap ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

The inclusion of the <div> tag disrupts the functionality of the Material UI Grid

While attempting to enclose my element within a <div> that is nested inside the <Grid>, I realized that this was causing the <Grid> layout to break! Surprisingly, when I tried the same approach with Bootstrap grid system, this issue did n ...

HTML: Hover effect does not work for icons when hovered alongside anchor elements within a list item

I wanted to add a special effect to my navigation list items: When the mouse hovers over the anchor tags of the list items (or even in the active state), I wanted the image in the <span> to be replaced with a colored version of the image. The color o ...

Retrieve information using Angular's EventEmitter

Recently I started learning Angular and encountered a challenging issue that has kept me occupied for the past few hours. I have implemented a parent-child relationship between two components, with a need to share a boolean variable from the parent to the ...

Differences between NgModel and ngModel in Angular 2

Just starting to learn Angular2, I have been reading blogs about it and stumbled upon NgModel and ngModel. I know that [(ngModel)] is used for two-way binding. Could someone clarify the distinction between the two? ...

Switching the class for the pseudo-element :after

Consider a scenario where there is a button: <button href="#" class="search no-style search-active" style="display: inline-block;"> <div class="pointer" style="display:none">::after</div> </button> Upon activation of the button, ...

Stacking components when scrolling in CSS to create a scrolling effect

I've been attempting to replicate the scrolling animation seen on this particular website: . The effect involves keeping the previous content in place while new content stacks on top as you scroll. I have experimented with using position:sticky and ad ...

Retrieve error information from ResponseContentType.Blob request type

I am currently struggling with an issue related to making a request of type ResponseContentType.Blob and receiving an error message when the call fails. The code I am using is quite simple: let headers = new Headers({'Content-Type': 'appl ...

Creating a custom design for input outline borders using CSS3

My CSS3 code is structured as follows: input[type="text"], input[type="date"], textarea, input[type="radio"], input[type="number"], input[type="time"], input[type="password"] { background: #ffffff; /* Old browsers */ /* IE9 SVG, ne ...

Is it feasible to preserve the HTML form content data even after refreshing the page?

Can someone offer a suggestion that doesn't involve using Ajax? I'm wondering if there is a way to achieve this using JavaScript/jQuery or some other method. Here's my issue: When submitting a page, the action class redirects back to the sa ...

Is there a way to set the canvas size to match the exact window size in pixels without being affected by the browser's zoom factor?

I'm currently developing a website called sphere.mars2540.com. Is there a way in JavaScript or CSS to maintain a fixed canvas size regardless of the zoom level of the page, ensuring it always aligns with the actual pixels on the screen (even with 4k ...

Chrome's navigation zoom feature enhances the user experience by allowing for easy

My website has a responsive layout that functions perfectly on mobile Safari (iOS), but I've encountered an unusual issue when using Chrome on Android. Whenever I click on a link in the vertical navigation that is not at the end, Chrome opens a sort o ...

Personalized labels for your JQuery Mobile sliders

Struggling to make this work correctly, I aim to introduce tick marks and custom labels into jQuery Mobile's slider widget. My goal is to add tick markers at 0, 25, 50, 75, and 100 with a unique string above each tick. Additionally, I want these label ...

The sticky top feature of the Bootstrap 4 navbar does not function properly when it is nested inside a div

I am just getting started as a beginner working on a Web application and utilizing Bootstrap 4 for my web design. I have a quick question that needs some clarification. When the code is structured like this, the Navbar does not stay fixed at the top: < ...