Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 make components overlap each other

Tags:

html

angular

Angular 2 puts a component under or next to another by default.

Is it possible to get them to overlap at will?

Thanks.

like image 317
Ionut Iliescu Avatar asked Sep 14 '25 04:09

Ionut Iliescu


1 Answers

A component is nothing more than an HTML element. You have to use css to have them overlap. To target the component itself, you have to use the :host selector:

@Component({
   selector: 'app',
   template: `
       <a-component></a-component>
       <b-component></b-component>
   `
})
export class AppComponent{}

a-component

@Component({
   selector: 'a-component',
   template: 'I am A',
   style: [`
      :host {
          position: fixed, 
          top: 0,
          left: 0
      }  
   `]
})
export class AComponent{}

This component will overlap the other component:

b-component

@Component({
   selector: 'b-component',
   template: 'I am B',
   style: [`
      :host {
          position: fixed, 
          top: 0,
          left: 0
      }  
   `]
})
export class BComponent{}
like image 60
Poul Kruijt Avatar answered Sep 16 '25 18:09

Poul Kruijt