1

I have a component which I'm inherits (including its css style) and I would like to change one of its attributes

This is the current CSS:

.captcha-main-image {
    width: 100%;
    height: auto;
}
<img class ="captcha-main-image" id="captchaImage" src="">

I would like to change its width value. This element is being generated by a different source and I can't ask the developer to change its value. Any chance I can do that by using !important somehow?

2
  • Of course you can do it with !important but you can also do it by using Javascript. The only thing is "When do you want to change the width ?" Commented Feb 12, 2020 at 12:51
  • 2
    Look for thee class the original component is using. And then override that class with !important tags. Commented Feb 12, 2020 at 12:53

3 Answers 3

1

Because of Angular's view isolation, you can override it only if you put the overrides in application's main style sheet.

In your application's styles.css, which is your application's main scss file - the one that is mentioned in agular.json, add the override:

.captcha-main-image {
   width: <your-value>
}

Typically, the !important is not required. Use it only if required.

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

Comments

1

If you want to override class within component adding !important will help Or if you want to override the css outside of that component use ::ng-deep .captcha-main-image can do.

1 Comment

ng-deep is deprecated.
1

You could add the class with max-width attribute to limit the width, e.g:

.captcha-main-image {
   max-width: 100px;
}

2 Comments

max-width does not override width, it only puts an upper limit on width's value.
Yes wording wasn't correct but outcome will have the desired effect, assuming 'width' value set at 100%. Will amend thanks.

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.