0

Component imports Bootstrap to reference variables or mixins:

@import "node_modules/bootstrap/scss/bootstrap";

HTML contains custom CSS elements but mostly standard Bootstrap elements:

<div class="container container-fluid h-100">
    <div class="row h-100">
        <div class="col-3 h-100">

The view encapsulation generates CSS from Bootstrap classes, and I would like to avoid it:

.h-100[_ngcontent-ukx-c19] {
    height: 100% !important;
}
.row[_ngcontent-ukx-c19] {
    --bs-gutter-x: 1.5rem;
    --bs-gutter-y: 0;
    display: flex;
    flex-wrap: wrap;
    margin-top: calc(-1 * var(--bs-gutter-y));
    margin-right: calc(-0.5 * var(--bs-gutter-x));
    margin-left: calc(-0.5 * var(--bs-gutter-x));
}

Is it possible to exclude Bootstrap from View Encapsulation and still be able to import Bootstrap into a component with enabled Encapsulation?

EDIT: Here is used angular.json: https://github.com/maciejmiklas/ng-doom/blob/20230124/angular.json

2
  • generally, when you use bootstrap.css you want to use in all your application, so you should add in angular.json. in the array "styles": "projects" --> "ClientApp" --> "architect" --> "build" --> "styles" Commented Jan 23, 2023 at 9:08
  • 1
    I feel you need not import node_modules/bootstrap/scss/bootstrap in your components.css Commented Jan 24, 2023 at 7:00

2 Answers 2

0

there is a section in angular.json called build->options->styles. styles listed there won't be encapsulated

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

1 Comment

I have it there, and it's not working: github.com/maciejmiklas/ng-doom/blob/20230124/angular.json . Probably, because my component imports bootstrap, this is necessary to use its variables/mixins.
0

It looks like it cannot be done. Here is a similar problem: Angular2: How to use bootstrap-sass with @extend and mixins in Angular-CLI?

As Eliseo pointed out - I have to remove bootstrap import from my component, which means I cannot use bootstrap imports inside components scss.

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.