Centralized Bootstrap Contact Form Design

I am currently in the process of setting up a contact form and my goal is to have this form centered on my webpage. However, I do not want it to take up the full width (col-md-12) of the page. Instead, I would like it to be the width of a col-md-6 located at the center of the page. The issue I am facing is that when I select col-md-6, the form appears on the left side of the page. How can I properly center it?

Here is the HTML code:

<div class="container">
    <div class="row">
        <div class="col-md">
            <form action="contact" method="post"> {{--action = where the data must go--}}

                <div class="form-group">
                    <label for="name">Name:</label>
                    <input type="text" class="form-control" id="name" placeholder="Your Name">
                </div>
                <div class="form-group">
                    <label for="email">Email address:</label>
                    <input type="email" class="form-control" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="325c535f5772574a535f425e571c515d5f">[email protected]</a>">
                </div>
                <div class="form-group">
                    <label for="mobile">Mobile Nr:</label>
                    <input type="email" class="form-control" id="mobile" placeholder="Mobile Nr should start with 08, 07 or 06">
                </div>
                <div class="form-group">
                    <label for="message">Your message...</label>
                    <textarea class="form-control" id="message" rows="3"></textarea>
                </div>

            </form>
        </div>
    </div>
</div>

Answer №1

To simplify the layout, consider adding two additional divisions using col-md-3 on either side of your form div like shown below:

<div class="container">
<div class="row">
    <div class="col-md-3">
    </div>
    <div class="col-md-6">
        <form action="contact" method="post"> {{--action = where the data must go--}}

            <div class="form-group">
                <label for="name">Name:</label>
                <input type="text" class="form-control" id="name" placeholder="Your Name">
            </div>
            <div class="form-group">
                <label for="email">Email address:</label>
                <input type="email" class="form-control" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="117f707c74517469707c617d743f727e7c">[email protected]</a>">
            </div>
            <div class="form-group">
                <label for="mobile">Mobile Nr:</label>
                <input type="email" class="form-control" id="mobile" placeholder="Mobile Nr should start with 08, 07 or 06">
            </div>
            <div class="form-group">
                <label for="message">Your message...</label>
                <textarea class="form-control" id="message" rows="3"></textarea>
            </div>

        </form>
    </div>
    <div class="cold-md-3">
    </div>
</div>

Answer №2

Consider applying the "m-auto" class to your col-md-6 div. Here is an example:

<div class="container">
<div class="row>
    <div class="col-md-6 m-auto">
        <form action="contact" method="post"> {{--action = where the data must go--}}
        
            <div class="form-group">
                <label for="name">Name:</label>
                <input type="text" class="form-control" id="name" placeholder="Your Name">
            </div>
            <div class="form-group">
                <label for="email">Email address:</label>
                <input type="email" class="form-control" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c727d71795c79647d716c7079327f7371">[email protected]</a>">
            </div>
            <div class="form-group">
                <label for="mobile">Mobile Nr:</label>
                <input type="email" class="form-control" id="mobile" placeholder="Mobile Nr should start with 08, 07 or 06">
            </div>
            <div class="form-group">
                <label for="message">Your message...</label>
                <textarea class="form-control" id="message" rows="3"></textarea>
            </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

Issues with undesirable spacing in CSS using the display property and table-cell display type

Having trouble grasping the concept of table and table-cell in css? See this example: http://jsfiddle.net/dd7h7/3/. HTML <div class="widget"> <div class="button"> <div class="content"> <div class="icon">A</div> ...

When a div is placed over an ul list, the list becomes hidden

I've been experiencing an issue across various platforms where I try to place a ul list on top of a div (image or background), but the list doesn't appear. I suspect it may be appearing behind the elements. I even tried adding z-index. Check out ...

Struggling to achieve consistent height for each div table box

Currently working on creating a table using CSS and divs, and I've got most of it set up except for the issue of uneven heights in the boxes. I've tried adjusting the heights and various commands, but to no avail. I'm unsure whether the prob ...

Sending input values to controller action parameters in CakePHP

I am working on an HTML form in which I need the URL output to be structured as follows: "example.com/mycontroller/action/mike/apple" Upon submitting the form using "post" method, the form values are not visible and can only be accessed through "_POST" ...

Firefox displays text smaller than Chrome

Hey there! I'm facing a little issue with my code. It renders correctly on Chrome (to the right), but on Firefox (to the left) it's a bit off. Any suggestions on how I can fix this? It usually corrects itself after a refresh (zoom in/out), but al ...

"Change the value of a style setting in React to 'unset

One of the components has CSS properties such as `right` and `bottom` that are set with a classname. I tried to override these values using the `style` prop but have only been successful in setting numerical values like `10px` or `0px`, not `unset`. Wha ...

What is causing my device form to malfunction - could it be the <form> HTML tag?

How can I resolve the issue with my devise sign up form not submitting when using the HTML "form" tag? Removing the tag allows everything to work correctly without any errors. <form> <div class="form-group"> & ...

Creating a two-column layout in CSS using div elements instead of tables allows for

Why is it so challenging to create a two-column form layout using CSS? All I'm trying to achieve is: Name: John Smith Age: 25 Description: A long text that should wrap if it exceeds the border, while still aligning with the first l ...

What is the sequence in which the browser handles CSS?

I have a specific class that is being styled in multiple places on my website. I am curious about the order in which the browser reads and applies these different styles. Can you explain this process to me? Inline Style <div class="yellowtag" sty ...

Is it possible to employ the columns tag within an HTML email design?

I am attempting to design an HTML newsletter that features three columns. In my initial attempts, I utilized the columns tag: <span style="-webkit-column-count: 3; -moz-column-count:3; column-count:3; -webkit-column-width: 160px; -moz-column-width:160 ...

What is the best way to reduce the size of a Bootstrap card image back to its original dimensions when

I am currently experimenting with a bootstrap card using HTML, CSS, and Bootstrap. My main focus right now is on how to shrink the image when hovering over it. The .card-header-img has a fixed height of 150px that I do not want to modify. What I want to a ...

Alter the dimensions and material displayed on Vue

In my Vue.js project, I have a topbar with two divs whose size and content need to be adjusted based on whether the user is logged in. If they are not logged in, it should look like this: <div id='search' width="400px"></div><div ...

Emojis representing flags displayed on screen

Is there an option to display a flag icon? For example, I am able to write Hello ...

Spider login page

My attempt to automate a log in form using Scrapy's formrequest method is running into some issues. The website I am working with does not have a simple HTML form "fieldset" containing separate "divs" for the username and password fields. I need to id ...

Ensure that the Bootstrap 5 modal and backdrop are sized to fit the parent container's width and height rather than filling the entire screen

Is there a way to limit the size of a Bootstrap 5 modal dialog and backdrop? The example below occupies 100% of the screen, can it be adjusted to cover only the parent main container? <main class="container-fluid pt-4 px-4" style="height ...

Using JQuery to create an animated slideToggle effect for a multicolumn list

I have a large list where each li element has a width of 33%, resulting in 3 columns: computers monitors hi-fi sex-toys pancakes scissors Each column contains a hidden UL, which is revealed through slideToggle on click. JQuery $('.subCate ...

How to showcase a solo form field in Django templates?

I am looking to only generate a forms.ChoiceField(choices=CHOICES) field in order to create a basic select HTML element. Instead of creating a new form class, I want a way to render just one form field in Django templates without the need for a form to ...

How can I utilize Bootstrap 4 to ensure that an image remains centered on the page even when the page size is adjusted?

Looking to insert a thumbnail in front of a video using Jquery. I managed to add the image, but facing an issue when resizing the page as the thumbnail should be centered. Here is the desired layout: https://i.sstatic.net/IDOb9.png However, my current res ...

Display the title tag when hovering over an image

Hey there! I'm looking to display the title tag of an image directly inside the image itself. Here's an example to illustrate what I mean: http://jsfiddle.net/51csqs0b/ .image { position:relative; width:200px; height:200px; } .ima ...

Is there a way to apply the 'absolute' or 'fixed' with a width of 100% to the parent div specifically, rather than to the window size?

I would like to create a banner similar to the one shown here: https://i.sstatic.net/SZLr9.png I am attempting to achieve this using 'absolute' or 'fixed' positioning. However, when I tried using 'left: 0 right: 0 top: 0', i ...