Position the button at the bottom right corner of the form

I created a basic webpage using Bootstrap 4 with a contact form and I am trying to figure out how to align the button to the bottom right instead of the bottom middle. Can anyone help me achieve this?

https://i.sstatic.net/0Dnz1.jpg

Below is the HTML code for the form:

      <div class="row">
        <div class="col center-block">
          <div class="contact">
            <h2>Contact</h2>

              <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88fcedfbfcc8fcedfbfca6ebe7e5">[email protected]</a>" method="post" enctype="text/plain">
                <div class="form-group">
                  <input type="text" class="form-control" id="contact-name" placeholder="Name" required>
                </div>
                <div class="form-group">
                  <input type="email" class="form-control" id="contact-email" aria-describedby="emailinfo" placeholder="Email" required>
                </div>
                <div class="form-group">
                  <input type="text" class="form-control" id="contact-message" placeholder="Your message" required>
                </div>
                <button type="submit" class="btn btn-dark">Send</button>
              </form>

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

Also, here is the CSS styling applied to buttons and form elements:

.form-control {
  width: 50%;
  margin: 0 auto;
  border-bottom: 1px solid #888;
  border-top: 0px;
  border-left: 0px;
  border-right: 0px;
  border-radius: 0;
  padding: 10px 0px;
}

input[type=text], input[type=email] {
  background-color: WhiteSmoke;
}

button {
  margin-top: 1em;
  margin-bottom: 2em;
}

Answer №1

Please utilize the following code snippet to create a button:

<div class="custom-btn">
  <button type="submit" class="btn btn-dark">Send</button>
</div>

Custom CSS:

.custom-btn {
    margin: 0 auto;
    text-align: right;
    width: 50%;
}

Answer №2

button {
 margin-top: 1em;
 margin-bottom: 2em;
 float: right;
 margin-right: 25%;
}

#contact { max-width: 960px; margin: 0 auto; }

form { padding: 75px 25px; }

To enhance the form layout, it is advisable to encapsulate it within a container and set its maximum width to 960px for better presentation.

Answer №3

All you have to do is add the d-flex class, no need for any additional inline CSS.

<div class="d-flex flex-row-reverse">
    <button type="submit" class="btn btn-dark" >Send</button>
</div>

That's all there is to it.

Answer №4

<div class="form-group col-md-12 text-right mt-2">

<button type="submit" class="btn btn-primary pl-4 pr-4">Click Here to Submit</button>

</div>

Answer №5

Consider this approach.

button {
    margin-left: 50%;
    float : right;
}

An illustration:

body {
  font-family: Arial, sans-serif;
  text-align: center;
}

h1 {
  font-family: "Playfair Display", serif;
  padding-top: 0.5em;
}

h2, h5 {
  text-transform: uppercase;
  /* Padding used instead of margins because whereas margins add space beyond element's box and therefore won't be colored, the inverse is true for padding  */
  padding: 0.5em 0;
  margin: 0;
}

.about p {
  padding: 0 4em 2em 4em;
  margin: 0;
  text-align: left;
}

.nav-link {
  text-transform: uppercase;
  color: white;
}

.nav-link:hover {
  color: white;
}

.hero-image {
  background-image: url(https://image.ibb.co/jEN7CS/workspace.jpg);
  /* Set a specific height */
  height: 100%;

  /* Position and center the image to scale nicely on all screens */
  background-position: center;
  background-repeat: no-repeat;
  /* Resizes background image to fill entire container */
  background-size: cover;
  position: relative;
}

.about {
  background-color: WhiteSmoke;
}

.portfolio {
  background-color: LightGrey;
}

.contact {
  background-color: WhiteSmoke;
}

/* Removes white space from sides of each column */
.col {
  padding: 0;
}

.footer {
  position: bottom;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 0.75rem;
  background-color: grey;
}

.footer-tag {
  color: white;
  text-align: left;
  padding: 15px;
}

.fab {
  float: right;
  padding: 10px;
  color: white;
}

.fab:hover {
    color: #4d4d4d;
}

.form-control {
  width: 50%;
  margin: 0 auto;
  border-bottom: 1px solid #888;
  border-top: 0px;
  border-left: 0px;
  border-right: 0px;
  border-radius: 0;
  padding: 10px 0px;
}

input[type=text], input[type=email] {
  background-color: WhiteSmoke;
}

button {
  margin-top: 1em;
  margin-bottom: 2em;
  margin-left: 50%;
  float : right;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
 <!-- Grey horizontal navbar that becomes vertical on small screens -->
  <nav class="navbar sticky-top navbar-expand-sm bg-dark">

    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link" href="#about">About</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#portfolio">Portfolio</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#contact">Contact</a>
      </li>
    </ul>

  </nav>

  <div class="container-fluid">
    <div class="row">
      <div class="col">
        <div class="hero-image">
          <div class="hero-text text-white">
            <h1>Name</h1>
            <h5>Web developer</h5>
            <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1c5d4c2c5f1c5d4c2c59fd2dedc">[email protected]</a>" method="post" enctype="text/plain">
              <button class="btn btn-dark">Contact Me</button>
            </form>
          </div>
        </div>
      </div>
    </div>

    <section id="about">
      <div class="row">
        <div class="col">
          <div class="about">
            <h2>About</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut hendrerit arcu quis lectus auctor, nec laoreet augue ornare. Proin vehicula id purus ac accumsan. Aliquam eu rutrum orci. Aliquam rhoncus ipsum sed nisi porta mattis. Cras euismod sed justo a vehicula. Maecenas nibh magna, auctor nec erat in, hendrerit blandit turpis. Curabitur laoreet viverra mi at consequat. Donec mollis tortor sem, vel pharetra magna mattis quis. Praesent erat dolor, lacinia at euismod quis, sodales eu orci. Fusce ut nibh dolor. Suspendisse potenti. Proin fermentum eros condimentum hendrerit mattis. Morbi libero nibh, tempus aliquam leo sed, elementum rutrum turpis. Pell...
          </div>
        </div>
      </div>
    </section>

    <section id="portfolio">
      <div class="row">
        <div class="col">
          <div class="portfolio">
            <h2>Portfolio</h2>
          </div>
        </div>
      </div>
    </section>

    <section id="contact">
      <div class="row">
        <div class="col center-block">
          <div class="contact">
            <h2>Contact</h2>

              <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e296879196a296879196cc818d8f">[email protected]</a>" method="post" enctype="text/plain">
                <div class="form-group">
                <input type="text" class="form-control" id="contact-name" placeholder="Name" required>
                </div>
                <div class="form-group">
                <input type="email" class="form-control" id="contact-email" aria-describedby="emailinfo" placeholder="Email" required>
                </div>
                <div class="form-group">
                <input type="text" class="form-control" id="contact-message" placeholder="Your message" required>
                </div>
                <button type="submit" class="btn btn-dark">Send</button>
              </form>

          </div>
        </div>
      </div>
    </section>

  </div> <!-- End of container-fluid -->

  <div class="footer">
    <a href="https://www.linkedin.com/in/name/" target="_blank"><i class="fab fa-linkedin fa-2x"></i></a>
    <a href="https://github.com/name" target="_blank"><i class="fab fa-github fa-2x"></i></a>
    <a href="https://codepen.io/name/"><i class="fab fa-codepen fa-2x"></i></a>
    <div class="footer-tag">
    <p>Created by Name.</p>
  </div>

Answer №6

To ensure your form remains centered, set its width to 50% and use margin:auto. Additionally, make the inputs inside the form spread out by setting their width to 100%. Wrap your button in a form-group and apply text-align:right to it for responsiveness.

Here's a fiddle for reference: https://jsfiddle.net/takius/j730vdmp/21/

body {
  font-family: Arial, sans-serif;
  text-align: center;
}

h1 {
  font-family: "Playfair Display", serif;
  padding-top: 0.5em;
}
...
...
...
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

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

HTML code displaying a fixed message at the top of the webpage

I'm working on a web page that has a lot of content. I need to have a message always visible at the bottom of the browser window, even when scrolling. Can anyone help me achieve this using simple CSS, HTML, jQuery, or PHP? Thanks! ...

Create a new division directly underneath the bootstrap column

Imagine having a bootstrap table like this: https://i.sstatic.net/kXHiP.jpg Now, if you want to click on a column and open a div with more details below it, is it achievable with CSS or JavaScript? https://i.sstatic.net/HIfkK.jpg I tried using the Metr ...

The amazingly efficient Chrome quick find feature, accessible by pressing the powerful combination of Ctrl + F, ingeniously

Currently using Google Chrome version 29.0.1547.62 m. I've employed the CSS attribute overflow set to hidden on the parent element, which renders some of my DIV elements hidden from view. Additionally, these concealed DIV elements are adjusted in pos ...

Exploring the functionality of maximizing and minimizing logic in an Angular Bootstrap modal popup

I'm currently utilizing Angular Bootstrap Modal Popup and I'd like to include options for Maximize and Minimize in addition to the close button. By clicking on the maximize option, the popup should expand to full screen, and by clicking on minimi ...

Align component within material-ui grid

Looking to center align the same cards but not just the grid component, I need the content itself to be equally distant from the borders and each other. I've searched and tried different solutions without luck. https://i.stack.imgur.com/aZj7H.png htt ...

Pictures are not aligned at the center of the bigger card container

I am facing an issue with centering images on my cards. The containers look fine on PC (centered) when smaller, but on responsive mode they revert back to the larger size and are left aligned. I want the images in the card containers to be centered regardl ...

Ways to horizontally line up text boxes

I need help aligning two textboxes next to their display names in a single line. I'm currently using dl, dt, and dd, but I'm having trouble getting them to align horizontally. Any suggestions on how to achieve this alignment would be greatly appr ...

Is it possible to place a secondary read more button next to the first one using CSS?

If you notice the code snippet, you will see that a "read more" button appears. How can I add another "read more" button to align side by side? I may even want to include three "read more" buttons, each opening in a separate modal box. ...

How do I create more space in Vitepress to prevent the text from feeling cramped and allow it to display in a larger area?

Below is the content of my index.md file: --- # https://vitepress.dev/reference/default-theme-home-page layout: home hero: name: "TP2" text: "Analyzing the code of TP2 by Breno Mazzali Medeiros Tomazelli and Philippe Bouchard" ta ...

Transform a dropdown menu into an inverted footer

I stumbled upon a unique dropdown menu design that I want to tweak and reverse, making it an innovative "dropup" menu that opens from the bottom to the top. Currently, this is what I have: HTML <div class="get-started"> <a href="#" id="get-s ...

What is the code to make an arrow symbol in CSS that represents 'greater than' symbol?

Can these arrows be created using CSS while maintaining compatibility with all browsers, including IE 6, 7, and 8? Or is using an image the only solution? Home > Products > Digital camera ...

Different floating divisions that are tightly packed adjacent to each other

I'm dealing with dynamically created divs that have variable content, all following the same CSS rules. My goal is to organize them into 2 columns without any space in between. I attempted to use float: left/right, but there still remains space at the ...

manipulating dropdown visibility with javascript

I'm feeling a bit lost on how to structure this code. Here's what I need: I have 5 dropdown boxes, with the first one being constant and the rest hidden initially. Depending on the option chosen in the first dropdown, I want to display the corres ...

Tips for creating a horizontal bar with CSS using the float property

Looking to create a horizontal scroll layout using CSS and floats? Here's my attempt, but I'm not getting the desired result. Flexbox isn't an option as it needs to be supported on IE. Take a look at my code and point out where I might have ...

Mosaic-inspired image gallery with HTML and CSS styling

Can anyone help me create a couple of styled "blocks" in HTML and CSS similar to the design shown in the image? I've searched for templates but can't find anything that matches my vision, so any assistance would be appreciated. (links not require ...

What is the process for triggering data-dismiss after the href has been activated?

Could someone help me with this issue? <a class='btn btn-danger' href='page.html'>Delete</a> I am trying to activate the "data-dismiss" attribute after the "href" is activated. My initial attempt was using this code: < ...

Looking for advice on designing a unique Gallery layout using CSS?

Tasked with converting various layouts, some of which utilize a specific layout pattern (refer to the image below.) I'm seeking advice on the most efficient way to use CSS to display a list of images in this manner without dividing items into separate ...

Interference in the output of .innerHTML leads to disruption

I have been working on a feature to display a calculated price based on the selected quantity for each individual product. I attempted to duplicate the code and modify variable names, but encountered issues with the increase/decrease buttons triggering mul ...

Guide to Adding a Video Background in Your ASP .NetCore MVC Web Application

As I dive into my latest project involving an ASP .NetCore web application, I'm encountering a roadblock when attempting to incorporate a video background. While there are numerous resources available for setting up video backgrounds in standard Html/ ...

When items are set to full width, material ui grid alignItems flex-start only affects the first row

I'm currently working with the material ui grid system, and I have a specific requirement. I need to create a grid container with a fixed height of 200px that accommodates full-width items. The challenge here is that I want the items to fill the conta ...