After switching over to Angular 6 from Angular 5, it's been noticed that the Bootstrap button styles are lacking proper

We recently completed an upgrade from Angular 5 to Angular 6.

The problem: After the upgrade, we noticed that Bootstrap button styles no longer have any margin spacing between them.

Current Bootstrap Version: 3.3.7

For instance, if you have the following in your html:

<div>
    <button class="btn btn-success">Success</button>
    <button class="btn btn-info">Info</button>
    <button class="btn btn-cancel">Cancel</button>
</div>

Prior to the update, there would have been visible space between these buttons.

We are exploring potential solutions or a universal CSS style that could address this issue.

Answer №1

During my recent project, I successfully managed to reinstate the default white spaces between Bootstrap buttons by implementing preserveWhitespaces as true in the main.ts file:

platformBrowserDynamic()
  .bootstrapModule(AppModule, { preserveWhitespaces: true})
  .catch(err => console.log(err));

I came across this solution at this source.

Answer №2

ConnorsFan's solution link perfectly addresses our problem.

In Angular 6, the angularCompilerOption: preserveWhitespaces is initially set to false for the application.

Answer №3

In addition to the response given, this issue arises due to the configuration of preserveWhitespaces.

The root cause lies in the fact that your template code removes all whitespace, such as:

<div>
    <button class="btn btn-success">Success</button>
    <button class="btn btn-info">Info</button>
    <button class="btn btn-cancel">Cancel</button>
</div>

When the whitespace is eliminated, the line breaks at the end of each button element are also removed. It is these line breaks that create the extra space, not margins between the buttons.

This explains why the buttons appear stuck together.

<div><button class="btn btn-success">Success</button><button class="btn btn-info">Info</button><button class="btn btn-cancel">Cancel</button></div>

You can implement a global solution or address the issue for specific components if necessary. Refer to https://angular.io/api/core/Component where it is explained that @components documentation offers the option to enable or disable this feature for individual components.

Alternatively, as suggested in the comments, you could add margin globally to all .btn classes. However, be cautious as this may lead to excessive margin between buttons if the setting changes again.

It is important to note that this is an HTML/DOM phenomenon, unrelated to Angular or CSS. The same effect can be observed with any inline elements by adjusting the line breaks/spaces between each element.

Answer №4

To add space margin between the buttons, simply include the btn-toolbar class in the div element. Here's an example:

 <div class="btn-toolbar">
  <button class="btn btn-success">Success</button>
  <button class="btn btn-info">Info</button>
  <button class="btn btn-cancel">Cancel</button>
</div>

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

What could be causing the error? And is there a way to successfully append the child div to the parent div?

Here is the error message that I am encountering: Uncaught TypeError: Cannot read property 'appendChild' of null at HTMLButtonElement.<anonymous> Error is located at app.js on line 7 const flexContainer = document.querySelector(&apo ...

Synchronization Problem between Background-Color Transition and Before/After Opacity Transition

I'm currently experiencing difficulties trying to fade in a navigation item using before and after pseudo-elements. When I hover over the nav item, it should transition its background-color from white to blue. It's a simple effect, but it also n ...

Adjusting Javascript code to convert numerical values in HTML table cells from thousands to millions

Does anyone know how to create a Javascript function for a web report that converts table values to thousands or millions by dividing or multiplying by 1000? The issue is that each value is clickable, meaning it is wrapped in an anchor tag. Is there a wa ...

What are the permissible child elements for an <a> tag?

Lately, I've been focused on structuring HTML code and it got me thinking about which elements are actually allowed as children of an <a> element. Can you help clarify? ...

Flexbox height not adjusting based on the length of the text within

I'm trying to create multiple child containers that contain an image and some text, with the container size adjusting based on the amount of text. The goal is for the image height to be 70% of the container's height, allowing the text to flow aro ...

When using Angular 2 formControl, manually changing the value may not be detected by the form

Having a simple form (as shown below), I am encountering an issue: Manually entering input value causes form.controls['myValue'].value to change If #myInput value is changed programmatically, the form completely ignores that change What could ...

What is the best way to retrieve HTML content using an Angular method?

Okay, so the title might not be the greatest...but I couldn't think of anything better: I want to emphasize search keywords in the result list...that's why I'm having trouble with this problem. CSS: .highlightText{ font-weight: bold; } In ...

Add the onclick function to $(document).ready for applying the desired functionality

I've been trying to create a fading effect for 3 divs on my page, similar to the one in this example: http://jsfiddle.net/x4qjscgv/6/ However, I want the fade animation to trigger only when a user clicks a button. I attempted to use the document.getE ...

The 'bind' property is not found within the 'void' data type

Here's the code snippet I'm working with: setInterval(this.CheckIfCameraIsAvailable(false).bind(this), 2 * 60 * 1000); private CheckIfCameraIsAvailable(forceCheck: boolean) { } I encountered the following error message: Property 'bin ...

Trying to update the +/- icon on an accordion dropdown, however, the local HTML file is not loading the JavaScript file. (Using Bootstrap 4)

I'm completely new to JS and struggling a bit, so please be patient. I've been searching online for a few days now without much luck. I'm using Bootstrap 4 and trying to create an accordion with a +/- icon that changes when expanded or colla ...

Can someone provide guidance on how to align the navigation bar to the right in Bootstrap?

Having trouble setting up the navigation menu on the right hand side with Bootstrap, like most modern websites. <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-togg ...

Angular - Implementing *ngIf based on URL parameters

Is it possible to display an element based on specific queryParams included in the URL? For example: ngOnInit() { this.route.queryParams.subscribe(params => { console.log(params); }); } If I want to achieve something similar to this: ...

Creating a compact Swiper slider: reducing image size without sacrificing full window coverage!

Utilizing Swiper to craft a slider that occupies the entire window, with a slight margin for a bar-- no issues there. (https://i.sstatic.net/qcGBA.jpg) However, the image I placed in for the slide () appears to be excessively enlarged. Is there a way to ...

Curved edges navigation bar design

Having trouble rounding the corners of my navigation bar. When I use border-radius: 15px;, it rounds all the corners of the <a> tag, but I only want to round the corners of the <li> tags to adjust the margins of the whole toolbar. Check out th ...

Implementing hover effect triggered by keyboard input

Is there a way to create a hover effect on a div when a specific key is pressed on the keyboard using jQuery? <div id="d-up" class="button"></div> Appreciate any help with this! Thank you. ...

Updating the logo image on mobile devices using responsive CSS styling

My goal is to show a different image to users on mobile devices using only CSS, as I am unable to access the HTML code. On mobile, I used display:none for the header-logo-image img { and then added a background-url to the div to successfully display my alt ...

Is there a way to prevent Javascript from modifying styles when printing?

Is there a way to prevent JavaScript from affecting styling during printing? For example, if I'm using JavaScript to hide certain content but want that content to be visible when printed. I have hidden a div using JavaScript and now I'm trying ...

Background image color not displaying correctly

I've been attempting to overlay a transparent color on top of a background image. While the background image is displaying correctly, I'm having trouble getting the color to show up. I noticed that this question has been asked before. I tried im ...

What is the best way to display rows in alternating red and green colors?

Currently, I am implementing the react table in my React project. I found valuable resources on how to use it at these links: https://github.com/tannerlinsley/react-table/tree/v6#codesandbox-examples and also here: https://www.npmjs.com/package/react-tab ...

Utilizing jQuery to dynamically update the selected item on a navigation bar

I have created a menu bar using the following HTML code: <ul id="menu-bar"> <li class="active"><a href="/" id="home">Home</a></li> <li><a href="/Club/" id="club">Club Quarter</a></li> <l ...