0

app.html

<app-chat></app-chat>

chat.html

<h1>Hello</h1>

chat.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-chat',
  templateUrl: './chat.component.html',
  styleUrls: ['./chat.component.css']
})
export class ChatComponent implements OnInit {
  constructor() { }

  ngOnInit() {
  }
}

chat.css

h1 {
    background-color: #000;
}

I need to know why the chat.css doesn't work in my browser. When I used CSS directly without chat component it works (like below).

app.html

<h1>Hello</h1>

app.css

h1 {
    background-color: #000;
}

So what is the solution?

4
  • Have you got the solution? Commented Nov 30, 2018 at 11:59
  • Hey, please also post the chat.component.ts Commented Nov 30, 2018 at 11:59
  • Could you share with us a working example of your problem in a fiddle/snippet? Because as you said the css inside your "chat.css" file should working if load corectly on your component, without necessarly put the css code in an outer ".css" file. Commented Nov 30, 2018 at 12:01
  • stackblitz.com/edit/angular-zpfcrx This is how it usually works Commented Nov 30, 2018 at 12:04

3 Answers 3

1

Try this!

::ng-deep h1{
   background-color: #000;
}
Sign up to request clarification or add additional context in comments.

2 Comments

in the chat.css ?
can you explain me the ::ng-deep functionality !
1

Try !important in your chat.css file

h1{
   background-color: #000 !important;
}

or

Use the powerful weapon of CSS style.css. But, before using it you have to set the class name for h1 tag.

chat.html

<h1 class="exampleClassName">Helo<h1>

Next, in your style.css file

.exampleClassName{
     background-color: #000;
 }

2 Comments

Advising to use !important is a very irresponsible thing to do :P
@inconnu I Updated my answer. Check it out
0

I did an example and it works: https://stackblitz.com/edit/angular-u99pry

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.