What is the best way to position my buttons on the right side and center the header?

I used the code below to display the interface seen here.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-lg-12">
    <div class="card m-b-30">
        <div class="card-header container-fluid">
            <div class="row">
                <h2 class="card-title">Customer Profile Types</h2>
                <div class="col-md-4 float-right">
                    <button class="btn btn-primary">Add</button>
                    <button class="btn btn-primary" style="margin-left: 1em">Update</button>
                    <button class="btn btn-primary" style="margin-left: 1em">Cancel</button>
                </div>
            </div>
        </div>


        <br>
        <div class="CustomerProfileTypes-body">

            <form>
                <div class="form-group row text-center">
                    <label for="Name" class="col-sm-2 col-form-label text-center">Name</label>
                    <div class="col-sm-5 d-flex justify-content-around align-items-center">
                        <input type="text" class="form-control" id="inputText">
                        <input class="form-check-input mt-2" type="checkbox" id="gridCheck">
                        <label id="gridCheck" class="mt-2"> Active</label>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

https://i.sstatic.net/hSTI9.jpg

However, I am aiming to achieve this output and properly align all elements on my interface.

The name field should be centered along with the textbox, and the checkbox alignment needs to be adjusted as well.

I am a beginner and would greatly appreciate any assistance.

https://i.sstatic.net/BEiy4.jpg

Answer №1

There are a couple of approaches you can take to achieve the desired result.

  1. Utilize bootstrap columns as you are currently doing.
  2. Implement flexbox

Approach 1 Make a slight alteration to your code:

<div class="row">
  <div class="col-md-6>
    <h2 class="card-title">Customer Profile Types</h2>
  </div>
  <div class="col-md-6 text-right">
    <button class="btn btn-primary">Add</button>
    <button class="btn btn-primary" style="margin-left: 1em">Update</button>
    <button class="btn btn-primary" style="margin-left: 1em">Cancel</button>
  </div>
</div>

Approach 2 Create the layout without using the bootstrap row and col, solely relying on flexbox (while still utilizing bootstrap classes).

<div class="d-flex justify-content-between align-items-center">
  <h2 class="card-title">Customer Profile Types</h2>
  <div>
    <button class="btn btn-primary">Add</button>
    <button class="btn btn-primary" style="margin-left: 1em">Update</button>
    <button class="btn btn-primary" style="margin-left: 1em">Cancel</button>
  </div>
</div>

Answer №2

To implement CSS effectively, consider utilizing flexbox with the "space-between" property on the parent div:

<div class="card-header container-fluid">

This configuration will create spacing between the h2 and B's elements.

Answer №3

<div class="col-lg-12" style="padding: 10px">
<div class="card m-b-30">
    <div class="card-header container-fluid">
        <div class="row">
            <h2 class="card-title" style="padding: 10px">Types of Customer Profiles</h2>
            <div align="right" class="col-md-8 float-right">
                <button class="btn btn-primary">Create New</button>
                <button class="btn btn-primary" style="margin-left: 1em">Update Details</button>
                <button class="btn btn-primary" style="margin-left: 1em">Cancel Operation</button>
            </div>
        </div>
    </div>


    <br>
    <div class="CustomerProfileTypes-body">

        <form>
            <div class="form-group row">
                <label for="Name" class="col-sm-2 col-form-label" style="text-align: center"> Name</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="inputText">

                    <input class="form-check-input" type="checkbox" id="gridCheck" style="margin-left: 2px" >

                    <label id="gridCheck" style="margin-left: 15px"> Activate Account </label>
                </div>
            </div>
        </form>
    </div>
</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

CSS image replacement; won't render properly

I'm currently working on implementing a hover image swap effect for my website gallery. The CSS code I have so far is below. While the original images in my HTML file are displaying correctly, the hover functionality is not working as expected. CSS: ...

How can I customize the appearance of a checkbox button in JavaFX?

I am currently working on styling a JavaFX scene with CSS in a stylesheet. The goal is to apply styles to all the "basic" elements of the scene when it loads. My issue lies in finding the correct code combination to change the background color of a button ...

Alert: CSS 4.0 Warning Validation - The value "rgb(0, 0, 0, 0.4)" is not valid for the "border" property

Wrapping up my asp core 3 project, I've been addressing various warnings that have popped up. However, one particular warning has me stumped. The CSS property in question is functioning perfectly, adding a touch of transparency to the black border. Wh ...

What is the method for extracting the initial H1 tag from a URL?

As I get ready for an upcoming interview, I am reviewing questions from a website. One question stumping me is: how can I write a function to extract the value of the first H1 element from a specified URL? The possible scenarios include: An H1 elemen ...

Is it possible to align Bootstrap buttons and input fields in a single row, and have the input field stretch to

I'm struggling to align Bootstrap buttons and input on the same line, with the input stretching horizontally while snugly fitting against the buttons. Here are my different attempts: https://i.sstatic.net/wuUsr.png In attempt #1: the button group an ...

Press the Instagram Follow Buttons by utilizing Selenium with Java

click here for image description Hello, I am currently working on automating the process of clicking follow buttons using Java. However, I'm encountering difficulties when trying to use JavascriptExecutor within a for loop. Below is the code snippet ...

What is the best way to position a title and subheading alongside an image?

I am currently working on developing a blog using php and html to enhance my coding skills. On my website, I have a special category where I display posts, the number of which can vary. Each post is composed of a title, a subheading, and a placeholder div ...

Having trouble with jQuery div height expansion not functioning properly?

Having a bit of trouble with my jQuery. Trying to make a div element expand in height but can't seem to get it right. Here's the script I'm using: <script> $('.button').click(function(){ $('#footer_container').anim ...

Display outcome prior to completion of the website processing in http/html/ajax

I am currently exploring ways to display a wait message in a web application while a task is running for an extended period of time. I am struggling with whether it is even possible. The issue seems to be that the website will only return to the user&apos ...

Tips on incorporating a class into a div generated within a contenteditable container

Take a look at this sample code: <div> Text.. <div id="editable-editor" contenteditable="true">Some Text Here...</div> </div> If you hit enter inside the #editable-editor after Some Text, it will generate a <div>Here...& ...

Change the WordPress Divi Builder nav bar to switch from transparent to white when scrolling or upon reaching a specific point on the page

Currently, I am in the process of revamping our company's WordPress website using the Divi Builder. For the past couple of days, I have been scouring the internet trying to find a solution that would allow the navigation bar to change CSS classes as t ...

Access data from an array using xpath in Chrome Console

Currently, I am utilizing the Google Chrome Console to extract an array of elements that are tagged with the class name attrValue. This is the line of code I am using: $x('//*[@class="attrValue"]'); Below is the output of my code: <td class ...

Using customized CSS code may not always be compatible with Bootstrap 5

One scenario I encountered was my attempt to change the background color of the body using style.css, but unfortunately, the code wasn't effective. Below is my reference to Bootstrap 5 and custom CSS: <link href="https://cdn.jsdelivr.net/npm/& ...

Immediate self-invocation occurs within a JavaScript function

My goal is to dynamically create a DOM button object with JavaScript, and it seems to be happening perfectly fine. However, I'm facing an issue where if I try to assign another JavaScript function to one of the buttons, the other script triggers itsel ...

After deploying DRF, the CSS in Django admin is not displaying

After developing a web application using Django Rest Framework and React, I faced an issue during deployment on IIS. While the deployment is successful, I encountered a problem with the Django Admin where the styles were not displaying properly. This led t ...

Trouble aligning buttons in Internet Explorer with center alignment

Check out this jsFiddle link using Internet Explorer and another major browser: http://jsfiddle.net/6bv7j/1/ Within the jsFiddle, click on the "Add Question" button to see a new row appear below. This row contains two buttons - one labeled "Select All An ...

Align the div in the center horizontally

Looking at this page, my goal is to center the main #container div horizontally in relation to the page. In a typical scenario, I would simply add a CSS rule like this, #container { margin: 0 auto } However, the layout of this specific page (which I didn ...

Distinct styling for the start and subsequent lines of an anchor element using ::before pseudo-element

I'm currently working on a project that requires adding a decoration in front of some anchor links (A). Right now, I am using ::before to achieve this. However, there is an issue where some of the links will line-break and the second line and subseque ...

Anticipated a JavaScript module script, but the server returned a MIME type of text/html as well as text/css. No frameworks used, just pure JavaScript

I have been attempting to implement the color-calendar plugin by following their tutorial closely. I have replicated the code from both the DEMO and documentation, shown below: // js/calendar.js import Calendar from '../node_modules/color-calendar&ap ...

The table printing settings are not compatible with portrait and landscape orientations

I am facing an issue with printing a table on my webpage. When I try to print using Control+P or window.print();, the width of the table does not adjust properly for portrait or landscape orientation. The table ends up exceeding the paper width. How can I ...