Ways to stop bootstrap from taking over the current styles in your application

Utilizing ng-bootstrap in my angular-app to create a popover, resembling something like https://i.sstatic.net/RPU49.png. I have incorporated custom fonts in the body which are specified in the styles.scss file as:

$r-typography: mat-typography-config(
  $font-family: 'TedNext, sans-serif'
);
$f-typography: mat-typography-config(
  $font-family: 'Yolo, sans-serif'
);
html[realm=r] {
  @include mat-core($r-typography);
  box-sizing: border-box;
  font-family: TedNext, sans-serif ;
}

html[realm=f] {
  @include mat-core($f-typography);
  box-sizing: border-box;
  font-family: Yolo, sans-serif ;
}

If the bootstrap import is removed from the styles.scss, the font appears like https://i.sstatic.net/48dSa.png, and the styling for the popover is lost as well https://i.sstatic.net/IcW8b.png.

Upon importing bootstrap.scss into styles.scss, the text becomes bold https://i.sstatic.net/xISyf.png, but the default fonts get overridden by bootstrap https://i.sstatic.net/Hv9jK.png.

The following code shows the button with mat-icon:

<button mat-icon-button matSuffix
                      popoverClass="popoverBackground"
                      ngbPopover="{{ 'PAYMENT.CREDIT_CARD.CVV_INFORMATION' | translate }}"
                      container="#checkId"
                      tabindex="-1"
                      type="button"
                      onclick="this.blur()"
                      [autoClose]="true"
                     class="cvv-info-button"
              >
                <mat-icon>info</mat-icon>
              </button>

Any suggestions on how to prevent bootstrap from overriding the normal fonts?

Answer №1

The rule in .css that holds the highest specificity will be given priority.

Ensure that your custom .css rules are tailored to be more specific to your elements.

For instance:

Consider this html structure:

<div class="base">
   <div class="child">
      text
   </div>
</div>

And these .css styles:

.child {
   color: red
}
.base .child {
   color: black
}

In this case, the second rule is more specific and the text will appear black. To override it, you can make the first rule more specific by adding additional selectors:

.black div.child {
   color: red
}

Answer №2

Combining Angular Material and Bootstrap CSS can be a recipe for frustration. It's best to steer clear of mixing them together. For further insights, check out this detailed conversation on the compatibility of Angular Material and Bootstrap CSS.

Answer №3

Integrating bootstrap with angular material has proven to be quite a challenge, as mentioned in various responses on this topic.

The issue arises when the bootstrap styles are unintentionally applied to the body of the webpage:

To address this problem, I had to go ahead and override the bootstrap styles like so:

html[realm=r] {
  @include mat-core($r-typography);
  box-sizing: border-box;
  font-family: TedNext, sans-serif ;

 body{
    font-family: TedNext, sans-serif;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How come my Bootstrap container columns are not remaining evenly divided into four parts?

Struggling to split a section of my project into 4 equal parts using the bootstrap col attribute. Unfortunately, every time I try, the last container ends up breaking and shifting below the other 3, creating an unsightly code layout. index.html <sec ...

When the mouse leaves the area, I would like the iframe within the div to be refreshed

When you hover over the button on the right, a slide panel appears with an iframe. Each time this page loads, it has a different background. I want a new background to load every time there is a new hover, requiring a refresh of the div. How can I achieve ...

IE's inconsistent float alignment causing display issues

My challenge is getting my div elements to float correctly in Internet Explorer. They are displaying perfectly in Chrome and Firefox, but IE seems to be messing up the code. The jsfiddle link showcasing the issue can be found here: http://jsfiddle.net/vlya ...

Navigating a stationary div within an overflowing container: Key steps

I've been grappling with this issue for quite some time. I'm in need of a div that remains fixed in position when its parent is scrolled horizontally, yet moves along with the content when scrolled vertically. The key is to ensure that the scroll ...

Discover the absent style attributes within an HTML code in C# and incorporate them

Currently facing a challenging situation where I have a C# string with html tags: string strHTML = "<span style="font-size: 10px;">Hi This is just a section of html text.</span><span style="font-family: 'Verdana'; font-size: 10px; ...

Interactive table with dynamic data retrieval

I need help displaying data dynamically from a datatable using an API. The API I am working with is located at this URL and I am utilizing the bootstrap4 datatable. You can also find my code on this JSFiddle. Can someone provide guidance or an example on h ...

The navigation bar is obscuring the header on my website

I am facing an issue with creating a navigation bar that covers up the header text. I tried adjusting the margins to fix this problem but ended up moving the header along with the navigation bar. How can I ensure that the navigation bar remains fixed witho ...

What is the best way to customize the appearance of an XML snippet using Greasemonkey?

I am attempting to customize an XML fragment retrieved from a server response using a Greasemonkey script. Take a look at this sample XML fragment from w3schools.com: <note> <to> Tove</to> <from>Jani</from> <heading ...

Dealing with a challenge: X-frame-options sameorigin issue when loading an iframe from a distinct subdomain with Spring Boot and

Whenever I try to display an iframe from a Spring Boot API on my Angular app, which are in the same domain but different subdomains (e.g. app.domain.com, api.domain.com), I keep getting "Refused to display ' ' in a frame because it set 'X-Fr ...

Engaging SVG Experience: Alter the color of one element by hovering over another

I'm currently working on creating an interactive SVG map. I have successfully incorporated code from Illustrator into an HTML file and managed to change the fill color of certain paths when hovering over them. However, I am facing an issue where a whi ...

Struggling with Getting My Animation to Function Correctly

I am trying to create a JQuery Animation that will move a div covering a text box up into the border when clicked. Despite multiple attempts, I can't seem to get the animation to work properly. Any suggestions? JavaScript function moveup(title,text ...

The workspace does not have the 'production' configuration set up - Angular

Encountering an error in my Angular application while running ng serve --prod on Windows 10. An unhandled exception occurred: Configuration 'production' is not set in the workspace. See "C:\Users\User\AppData\Local& ...

Ways to give a z-index to create distance between an image and a div's border

Fiddle: https://jsfiddle.net/0qqnvrdg/ HTML: <div class="loading"></div> CSS: body { background: #0d8aa5; } .loading { position: absolute; left: 50%; top: 25%; /*margin: -60px 0 0 -60px;*/ background: #fff; width: 200px; ...

What is the best way to mirror an image using CSS3?

I'm looking to create a minimalist front page for my wife's jewelry website. I envision a simple layout with a blurred background and a sleek title at the top. In the center of the page, there will be several sections dedicated to different types ...

Steps for making a website with password protection

I'm currently working on building my website and I want to implement password protected JavaScript code for access. Will I also need to update my CSS, or is it just a matter of adjusting my HTML code? ...

The Angular router seems to be refusing to show my component

My Angular 2 App includes a Module called InformationPagesModule that contains two lazy load components (Info1 Component and Info2 Component). I would like these components to load when accessing the following routes in the browser: http://localhost:4200/ ...

Tips for separating <td> tags within a series of <td>

I am working with the HTML code provided below. <tr> <td class="slds-cell-wrap" data-label="">Category</td> <td class="slds-cell-wrap break" data-label=""><strong> Test </strong></td> <td clas ...

"Utilizing a media query to display an anchor link at the top based

How can I create a "Back to Top" link that automatically scrolls mobile and tablets to the top of the page? Usually, I would achieve this using JavaScript by detecting the window and body height. Is it possible to accomplish this using a media query? @me ...

Achieving a full-page color background for a single-element loading animation: a step-by-step guide

Currently, I have a single HTML div dedicated to serving as a loading screen element. My goal is to incorporate a full-page background color behind the rotating image. Essentially, I want the animated image to be displayed on top of a solid colored backgro ...

Is there a way to modify the color scheme of the hamburger icon

I'm experiencing difficulties changing the color of a hamburger icon. I've searched for the specific code responsible for the color change, but I haven't been able to locate it. Ideally, I want the color to be white, but on small screens, i ...