4

I am having a bizarre issue whilst creating my first Angular2 app.

I am applying some CSS to a component host (example-component) yet it doesn't appear in the browser?

This is my first time posting for Angular in SO, so hopefully I include everything needed to attain some help.


example.component.ts

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

@Component({
  selector: 'crate',
  templateUrl: './app/folderA/folderAB/crate.html',
  styleUrls: ['./app/folderA/folderAB/crate.css']
})
export class MyComponent {}


index.html


crate.html

<div class="background">
    <div class="content">
        <p>Content</p>
    </div>
</div>


crate.css

:host-context(.lg){
    width: 100%;
    background-color: #000;
    border-radius: 25px;
}


What I don't understand, is that I open this in chrome & firefox, and I see the following CSS stated under rules for example.component.

.lg[_nghost-ims-2], .lg [_nghost-ims-2] {
    width: 100%;
    background-color: #000;
    border-radius: 25px;
}

Firefox

It is correctly applying the CSS to example-component, but it is not being displayed / rendered in browser. What am I doing wrong / missing?


EDIT

The exact same issue applies even if I change crate.css to:

crate{
    width: 100%;
    background-color: #000;
    border-radius: 25px;
}
10
  • change 'styleUrls' to 'styles'? Commented Oct 16, 2016 at 5:21
  • change :host-context (.lg){} to :host .lg{} and check. Commented Oct 16, 2016 at 5:27
  • @micronyks Doesn't apply it to the element. Commented Oct 16, 2016 at 5:32
  • There are many other ways to do it. Commented Oct 16, 2016 at 5:35
  • Its working. maybe browser issue. try to run with chrome. Commented Oct 16, 2016 at 5:39

1 Answer 1

4

Any component with an unrecognized tagName like <crate></crate> is created as a HTMLUnknownElement and has empty values for all the style properties, if you want it to behave like a div then add display: block; to your stylesheet.

See Browsers' default CSS for HTML elements for additional resources on the default css for different browsers.

Sign up to request clarification or add additional context in comments.

1 Comment

I will check this out as soon as possible - thanks for the answer.

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.