How to Position Bootstrap 4 Button in Alignment with Additional Content in Angular 6

Bootstrap 4 has presented me with a challenge where my Buttons are not aligned properly ....https://i.sstatic.net/rViCT.png

To resolve this issue, I took matters into my own hands and wrote some custom CSS

.btn-success, .btn-danger, .btn-primary {
margin-left: 30px;
margin-right: -15px;

}

https://i.sstatic.net/XoZ6Z.png

Html

<div class="row">
<div class="col-xs-12">
<form>
  <div class="row ml-auto">
    <div class="col-sm-5 form-group">
      <label for="name">Name</label>
      <input type="text" id="name" class="form-control">
    </div>
    <div class="col-sm-2 form-group">
      <label for="amount">Amount</label>
      <input type="number" id="amount" class="form-control">
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12">
      <button class="btn btn-success" type="submit">Add</button>
      <button class="btn btn-danger" type="submit">Delete</button>
      <button class="btn btn-primary" type="submit">Clear</button>
    </div>
  </div>
</form>
</div>
</div>

Despite trying to use bootstrap classes ml-auto and float-right, the alignment issue remains. I am convinced that there must be a better solution to tackle this problem ...

Answer №1

Test it out with:

class="text-right"

Make sure to adhere to the guidelines outlined in the Bootstrap grid documentation.

"Rows act as containers for columns... In a grid structure, content should be placed inside columns and only columns can serve as direct children of rows."

<container>
  <row>
    <col-12>
      <card/>
    </col>
    <col-12>
      <card/>
    </col>
    <col-12>
      <card/>
    </col>
  </row>
</container>

or,

<container>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
</container>

Answer №2

To create a parent flex-container and apply the CSS property justify-content: space-between, follow this example:

.flex-container {
  display: flex;
  width: 150px;
  justify-content: space-between;
}
<div class="row">
<div class="col-xs-12">
<form>
  <div class="row ml-auto">
    <div class="col-sm-5 form-group">
      <label for="name">Name</label>
      <input type="text" id="name" class="form-control">
    </div>
    <div class="col-sm-2 form-group">
      <label for="amount">Amount</label>
      <input type="number" id="amount" class="form-control">
    </div>
  </div>
  <div class="row">
    <div class="flex-container col-xs-12">
      <button class="btn btn-success" type="submit">Add</button>
      <button class="btn btn-danger" type="submit">Delete</button>
      <button class="btn btn-primary" type="submit">Clear</button>
    </div>
  </div>
</form>

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 is the proper method for incorporating text into d3.js nodes?

As I venture into the world of d3.js, I've decided to experiment with some sample code from this particular page and tweak it according to my needs. My main goal is to include TEXT within the colored nodes. Although these nodes already have a title p ...

Ionic 3 Local Notification spamming a particular page with excessive pushes

Recently starting out with Ionic, I encountered an issue while developing a basic app that should display a specific page by opening a Local Notification. The problem arises when I create multiple notifications – after clicking on the second notification ...

Problems with cookies causing log-in sessions to expire

As I continued to work on my website today, I noticed that every time I try to test it, I have to log in to my account again. This seems strange because I set up the cookies to expire after 30 days. It appears that they are not functioning properly, and un ...

Accessing locally stored files on the localhost

My attempts to access a PDF file from my local host through a PHP file have been unsuccessful. The link does not respond, although it works when I convert the file to HTML and place it in drive C or D. It seems that the issue lies with the use of HTTP on t ...

Is there a way to incorporate a preload page in Jekyll?

I recently stumbled upon this unique preload page style on Codepen and I must admit, my knowledge of JS is quite limited. body{ display: flex; justify-content: center; align-items: center; height: 870px; background-color:#000; po ...

HTML Element Split in Two by a Line in the Middle

Greetings to all, after observing for a while I have decided to make my first post here (and just to clarify, I am an electrical engineer, not a programmer). I am in search of creating a unique element in HTML where I can detect clicks on both its upper a ...

Avoid allowing users to accidentally double click on JavaScript buttons

I am working with two buttons in a Javascript carousel and need to prevent users from double-clicking on the buttons. Below is the code I am using: var onRightArrow = function(e) { if (unitCtr<=unitTotal) { unitCtr++; TweenLite.to(p ...

Enhance your Bootstrap navbar by seamlessly integrating icons into the collapse feature

What is the best way to include an icon with a link in a collapsed navbar using Bootstrap 4? https://i.sstatic.net/ZAVBe.png ...

What is the reason behind negative numbers appearing as "5-" rather than "-5" in the basic calculator coded using HTML and JavaScript?

As I am practicing my coding skills, I encountered an interesting issue. Any operation that results in a negative number displays as wrong, but when using console.logs it shows the correct result. Can someone explain why this is happening? <!DOCTYPE h ...

Having trouble with table sorting in Jquery?

I am a beginner in the realm of Jquery and web programming. Recently, I attempted to implement the tablesorter jquery plugin for one of my projects but encountered issues with making it work properly. In search of a solution, I turned to Stack Overflow. C ...

Ways to modify the gap between buttons using CSS

I am faced with a design challenge on my home page. I want to add some spacing between the buttons so they are not too close to each other, but for some reason margin-top and margin-bottom properties are not working as expected. Can you help me figure out ...

A New Approach to Initializing Web Pages in ASP.NET (with a Surprising Twist)

Well, I've encountered quite the puzzling issue with a project I'm working on (it could even make it to the Daily WTF), and I'm hoping for some help in finding a solution. (Apologies in advance for the lengthy explanation...) About a month ...

Innovative sound system powered by React

I am working on implementing a music player feature on a website where users can select a song and have it play automatically. The challenge I am facing is with the play/pause button functionality. I have created all the necessary components, but there see ...

Trigger a dispatched action within an NGRX selector

I want to ensure that the data in the store is both loaded and matches the router parameters. Since the router serves as the "source of truth," I plan on sending an action to fetch the data if it hasn't been loaded yet. Is it acceptable to perform the ...

Utilizing Jquery to Load JSON Arrays as Tooltip Messages

I have successfully loaded the descriptions of my JSON variable into my script as tooltips. However, I am encountering two issues: When hovering over one sentence in my table, tooltips for all four sentences appear. It seems like I am unable to revert my ...

Revamp the hues of numerous elements simultaneously using just a single click!

Is there a way to change the colors of various elements (footer, divs, text) background and text color at once using just one button? I attempted to use JavaScript buttons, but I'd prefer not having to name each individual object's button in orde ...

Verify the visibility of the toggle, and eliminate the class if it is hidden

I have implemented two toggles in the code snippet below. I am trying to find a solution to determine if either search-open or nav-open are hidden, and if they are, then remove the no-scroll class from the body element. $(document).ready(function() { ...

Is it possible to craft poetic lines with indents in HTML using blockquotes, pre, or dd tags?

I am struggling to format a few lines of text with indentations using HTML. Here is an example I found: HERE Below is my attempt: <p><code>"Knowing is not enough. We</code></p> <p><blockquote><code>must apply. Wi ...

Every time I attempt to create a new ionic project using angular through the console, I encounter the error message: "npm ERR! Cannot read properties of undefined (reading 'isServer')"

Having an issue with npm where it is giving the error "Cannot read properties of undefined (reading 'isServer')." I have updated npm to the latest version and tried force-clearing the cache, but the issue persists. Can anyone provide assistance? ...

Using jQuery to disable a checkbox when its value matches any elements within an array

I am attempting to programmatically disable checkboxes upon page load based on certain conditions, specifically when the checkbox values correspond to records in my database. After researching solutions such as this one and here, I noticed that the main d ...