How to align 3 buttons in a div using CSS

My design has 3 buttons that I want to always remain centered on the page, but they seem to skew off-center as the window widens (as shown in the image).

What HTML/CSS code can I use to ensure that these buttons are perfectly centralized at all times?

It appears that they skew more towards the left side, creating extra space on the right.

https://i.stack.imgur.com/lU8EA.png

    <body>
        <h1 class="title">Creative Checker</h1>
        <div class="row">
            <div class="col-12 col-md-10 offset-md-1">
                <div class="alert alert-success" style="display: none">
                </div>
                <div class="alert alert-danger" style="display: none">
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <p class="text-center">
                            1. Select product type:
                        </p>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="col-lg-4">
                        <button type="button" id="btn-snapshot" class="btn btn-secondary col-lg-12">Snapshot</button>
                    </div>
                    <div class="col-lg-4">
                        <button type="button" id="btn-tmd" class="btn btn-secondary col-lg-12">TMD</button>
                    </div>
                    <div class="col-lg-4">
                        <button type="button" id="btn-bpush" class="btn btn-secondary col-lg-12">Behavioural Push</button>
                    </div>
                </div>
                <div class="row">                   
                    <div class="col-lg-12">
                        <p class="text-center">
                            2. Upload folder/images:
                        </p>
                        <form action="server.php"
                            class="dropzone"
                            id="my-awesome-dropzone"
                            onsubmit="onSubmit()">
                            <!-- <select name="product-type" id="product_type">
                                <option value="snapshot">
                                    Snapshot
                                </option>
                                <option value="TMD">                                
                                    TMD
                                </option>
                                <option value="b-push">
                                    Behavioural Push
                                </option>
                            </select> -->                       
                        </form>
                    </div>
                </div>          
            </div>  
        </div>
#btn-snapshot {
    z-index: 39;
    width: 250px;
    min-height: 15px;
    background-color: #75ACE0;
    border-radius: 20px;
    position: relative;
}

#btn-tmd {
    z-index: 39;
    width: 250px;
    min-height: 15px;
    background-color: #75ACE0;
    border-radius: 20px;
    position: relative;
}

#btn-bpush {
    z-index: 39;
    width: 250px;
    min-height: 15px;
    background-color: #75ACE0;
    border-radius: 20px;
    position: relative;
}

Answer №1

To ensure the button is centered, include the text-center class in the col-lg-4 element.

If you are not using bootstrap, insert the following CSS code into your document:

.text-center{
    text-align: center;
}

Answer №2

Based on the current information provided, my recommendation is to make sure that class row mb-3 has a width of 100%.

.row mb-3 {
  width: 100%;
}

If this solution doesn't solve your problem, please share your CSS code for further analysis. This will help us pinpoint any potential issues more effectively.

Answer №3

Snippet of HTML code: <div class="wrapper">

<div class="block">

<div class="box">

` <button type="button" id="btn-preview" class="btn btn-secondary col-lg-12">Preview</button>`

</div>

<div class="box">

 ` <button type="button" id="btn-edit" class="btn btn-secondary col-lg-12">Edit</button>`

</div>

`<div class="box">`

  `<button type="button" id="btn-send" class="btn btn-secondary col-lg-12">Send</button>`

</div>

</div>

</div>

Styling with CSS:

.block {
  background: #f8f9fa;
  margin-top: 20px;
}

.box {
  border: solid 0px #6c757d;
  padding: 10px;
}

If you want to see the live demo, check out this link.

Answer №4

Do you resemble this?

.row {
  display: flex;
  justify-content: center;
  flex-flow: row wrap;
  align-items: center;
}
.btn {
  color: white;
  background: #45C9F8;
  border: none;
  padding: 8px 40px;
  border-radius: 50px;
}
<div class="row mb-3">
    <div class="col-lg-4">
        <button type="button" id="btn-snapshot" class="btn btn-secondary col-lg-12">Snapshot</button>
    </div>
    <div class="col-lg-4">
        <button type="button" id="btn-tmd" class="btn btn-secondary col-lg-12">TMD</button>
    </div>
    <div class="col-lg-4">
        <button type="button" id="btn-bpush" class="btn btn-secondary col-lg-12">Behavioural Push</button>
        </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

What is the best way to incorporate a unique box shadow onto my svg image?

While I've seen a similar question here: How to add box-shadow to a svg path circle shape, I am struggling to grasp how the transition from box shadow characteristics to SVG drop shadow characteristics was achieved. (Especially given that SVG Drop sha ...

Start fresh with your list styling in Sass/CSS

I'm attempting to revert ul and li elements to their default styles using a specific class, but I'm encountering difficulties in doing so. I've experimented with the inherit and initial values, but they haven't proven effective. This i ...

`Center the image on top of the text`

Currently, I am working with Bootstrap 4 to create a component that includes two tiles. Each tile has an icon image on the left side and a hyperlink on the right side. On desktop view, the tiles should be displayed horizontally and vertically centered. How ...

How was the background design accomplished on this particular website using CSS?

I've noticed that the background on this website scrolls and changes at various points. It transitions from blue to green with clouds moving. I'm curious about what term is used to describe this type of background effect (I don't think it&ap ...

I am experiencing an issue with the display inline feature not functioning properly in Firefox

I am working with Html code: <div class="login"> <form class="form-horizontal signin"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">Ema ...

Top technique for mirroring a website

Recently, I created a directory for a client's website. The site is fully operational, but the client would like a replicated version for testing and learning purposes. To create a full replica of his website, it will require hours of work to change ...

Semantic UI Footer allows you to easily create a stylish

Greetings! I'm new to the semantic-ui framework and I'm encountering an issue with the footer. My goal is to have the footer always stay at the bottom of the page without being fixed. Here's a snippet of my simple HTML code: <!DOCTYPE h ...

Building a Responsive Page with Bootstrap 4

I'm currently working on a design page with 2 boxes on the left side and 3 boxes on the right. It looks great on desktop, but I want the boxes to display individually on mobile devices and I'm having trouble figuring it out. Here is my code: < ...

What could be the reason for the discrepancy between my get_token() function and the value obtained from request.META.get("CSRF_COOKIE")?

Can anyone shed light on why I'm facing this particular issue? I am currently exploring the integration of Angular 17 as a Frontend with Django as a Backend. While validating a form, I encountered an issue where the token obtained from Django does no ...

What could be preventing me from setting a boolean variable within an Observable?

After retrieving data from the Service, I am attempting to hide a specific div element. Below is the HTML code: <progressbar *ngIf="isLoadingBootStockData" [value]="100" type="default"> </progressba ...

Having trouble with my Bootstrap 4 navbar button - what am I doing wrong?

After conducting research online, I found myself unable to resolve my issue due to my lack of proficiency in English. I apologize for any confusion caused and would like to revisit the topic. The problem lies with my navbar toggle that is not functioning ...

The dropdown menu failed to display properly as intended

I'm encountering an issue with the CSS for my menu. Here is a screenshot of the dropdown menu: Whenever I hover over the submenu, it drops down along with the parent menu container. Please take a look and let me know what might be causing this probl ...

Fluid and static containers in Bootstrap offer flexible and fixed-width layout

I am experimenting with combining fluid containers and fixed containers within a single page layout using Bootstrap. For example, I want to have a large image as a hero unit that spans 100% of the width and height of the viewport, or three column images e ...

The background image fails to show up on the mobile device display

Currently, I am working on an app with Ionic, but unfortunately, the background image is not showing despite all my efforts. I have gone through various solutions provided in previous questions, but none of them seem to work for me. Here is the CSS I am u ...

Error: JavaScript alert box malfunctioning

I am facing an issue with my JavaScript code. I have successfully implemented all the functionalities and can change the color of an image background. However, I am struggling to prompt a pop-up message when clicking on an image using "onclick". I have tri ...

When a CSS fluid layout includes a containing div with margin or padding, it may lead to

On my jsfiddle , the outermost wrapper div has a width of 100%. I am trying to create an inner div (tb_margin or tb_padding) where the content starts 40px from the left. I have attempted to use both margin and padding for this left spacing, but in both cas ...

Tips for designing adjustable text in bootstrap 4

Could someone please assist me with making text responsive using Bootstrap 4? I have searched everywhere but it's strange to see that there are no tutorials on this topic. Below are my codes in case you would like to provide guidance. <div class=" ...

Tips for Minimizing DIV Space with the Flex Property

I need some help with reducing the space between the individual content (1, 2, 3, 4) and its border in this Fiddle. As a newcomer to Flexbox, I'm unsure if there's an easy solution to this issue. Here is a visual representation of what I mean: ...

Turn off Chrome 69's autofill functionality

I've recently encountered an issue with Chrome's password autofill feature that has been troubling me for a few days now. This problem began when I was using Chrome version 69. After much trial and error, I found a solution by removing the id an ...

Validation of default values in contact forms

Obtained a free contact form online and hoping it works flawlessly, but struggling with validation for fields like "Full Name" in JS and PHP. Here is the HTML code: <input type="text" name="contactname" id="contactname" class="required" role="inpu ...