0

I am trying to do something like this in Angular:

css

header-wrap[icon="taco"] icon-element {margin: 1rem;}

HTML

<header-wrap icon="taco">
 <icon-element></icon-element>
</header-wrap>

But it will not work. Are attribute selectors "end of the road" selectors? Meaning you cannot select things after it? The strange part is that when I use document.querySelectorAll in chrome inspector it returns the element I want, but any attempt to write a style for this case fails.

2
  • By default, you can only access style of the component directly from that component. For more details, read the docs about view encapsulation. You could either disable that (which I would advise against) or pass styling as part of the @Input or @HostBinding. Commented Jul 26, 2021 at 16:15
  • Another options futhermore use your styles.css -the .css that is applied to all the app-:stackoverflow.com/questions/68443318/… Commented Jul 26, 2021 at 17:11

1 Answer 1

1

I tested your code and it works on my side! Your CSS code is right and it targets well the element you want.

The problem would apparently be that your tag icon-element is empty. When I added some text in it the CSS changes occurred.

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

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.