What is the best way to position a button to the right of a textarea?

I am facing an issue with my website that uses Bootstrap 4. The contact form in my design is beautifully aligned, but on my actual website, it appears misaligned. I have experimented with floats and tried organizing the form elements in rows and columns, but nothing seems to work.

Here is the snippet of CSS and HTML code I am using for the form:

footer input, textarea {
    background: #fff;
    border: none;
    -webkit-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    -moz-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    border-radius: 15px;
    display: inline-block;
} 
footer button.btn {
    display: flex;
    justify-self: flex-end;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 15px;    
}
<div class="col-md">
    <form action="" method="post">
      <div class="row">
        <label for="name">Name</label>
        <input type="text" name="name">
        <label for="email">Email</label>
        <input type="text" name="email"><br>
        <div class="form-group row">
            <label for="message">Subject</label>
            <textarea name="message" id="" cols="30" rows="10"></textarea>   
            <button type="submit" class="btn btn-info">Send</button>        
        </div>
      </div>
    </form>
</div>

If you want to see all of my code, you can check it out here.

Any help or suggestions would be greatly appreciated. Thank you.

Answer №1

You could experiment with utilizing the flexbox utilities in Bootstrap for your layout :)

input, textarea {
    background: #fff;
    border: none;
    -webkit-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    -moz-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    border-radius: 15px;
} 

footer button.btn {
    display: flex;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 15px;    
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container p-5 d-flex justify-content-center align-items-center" 
  <form>
    <div class=" d-flex justify-content-center align-items-center flex-column">
    <div class="form-group align-self-start">
      <label for="name" class="mx-1">Name</label>
      <input type="text" name="name">
    </div>
    <div class="form-group align-self-start">
      <label for="email" class="mx-3">Email</label>
      <input type="text" name="email">
    </div>
    <div class="form-group d-flex justify-content-center">
      <label for="message" class="mx-2">Subject</label>
      <textarea name="message" class="mx-2" id="" cols="30" rows="10"></textarea>
      <button type="submit" class="btn btn-info align-self-end mx-2">Send</button>
    </div>
  </div>
  </form>
</div>

Furthermore, here's a live demonstration for reference :)

Answer №2

Ensure that your button is placed outside of the form-group div

 footer input, textarea {
    background: #fff;
    border: none;
    -webkit-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    -moz-box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    box-shadow: 0px 1px 4px 2px rgba(0,0,0,0.16);
    border-radius: 15px;
    display: inline-block;
} 
footer button.btn {
    display: flex;
    justify-self: flex-end;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 15px;    
}
<div class="col-md">
                <form action="" method="post">
                    <div class="row">
                    <label for="name">Nombre</label>
                    <input type="text" name="name">
                    <label for="email">Email</label>
                    <input type="text" name="email"><br>
                    <div class="form-group row">
                        <label for="message">Asunto</label>
                        <textarea name="message" id="" cols="30" rows="10"></textarea>   
                             
                    </div>
                    <button type="submit" class="btn btn-info">Enviar</button>   
                    </div>  
                </form>
            </div>

Answer №3

Instead of resorting to custom CSS for alignment and spacing, explore the documentation and leverage Bootstrap.

<form action="" method="post">
    <div class="form-row mb-2">
        <label for="name" class="col-md-3 text-right">Name</label>
        <input type="text" name="name" class="col-md-7 form-control">
     </div>
    <div class="form-row mb-2">
        <label for="email" class="col-md-3 text-right">Email</label>
        <input type="text" name="email" class="col-md-7 form-control">
     </div>
    <div class="form-row mb-2">
        <label for="message" class="col-md-3 text-right">Subject</label>
        <textarea name="message" id="" cols="30" rows="10"  class="col-md-7 form-control"></textarea>
        <button type="submit" class="btn btn-info col-md-2 align-self-end">Send</button>
    </div>
</form>

Demo:

By following this approach, you can avoid the need for additional CSS.

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

Grid-based timekeeping design

Currently working on a clock grid layout and seeking some advice on the next steps. The layout has been created but still needs some adjustments to achieve perfection. What would be the most effective approach for correcting it? Would offsetting it using a ...

Tips for dividing the WordPress header navigation horizontally using separate PHP files

I am trying to customize my WordPress menu navigation by splitting it into two sections: left and right. I have added the menu function in the "functions.php" file to create the menu from the backend, and the frontend modifications will be done in the "hea ...

Issue with implementing custom fonts using @font-face

I've added custom @font-face styling to my CSS using a downloaded font, but it doesn't seem to be working. Below is my CSS code: @font-face { font-family: "Quicksand"; src: url("fonts/Quicksand/Quicksand-Light.otf") format("opentype"); } The f ...

Develop a custom script function for every instance of a @foreach loop

I have a challenge where I need to style automatically generated table rows by clicking on a button. Currently, my code appears as follows: @foreach($tours as $tour) <tr id="{{$tour->id}}"> <td> {{$tour->tournr}} &l ...

Why isn't the default value appearing on page load in jQuery?

I have a set of radio buttons with five different values. For each value selected, a corresponding span tag is generated with a description associated with that specific radio button option. Here's an example: <table class="jshop"> <tbod ...

My content is being obstructed by a single-page navigation system

I attempted to create a simplified version of the issue I am facing. Basically, I am working on a header with navigation that stays at the top of the page while scrolling. The problem arises when clicking on a section in the navigation. The screen scrolls ...

Adding a close button inside a circular background using HTML/CSS

I'm struggling to align the X inside the circle perfectly; they just don't seem to match up no matter what I try. Here's a glimpse: https://i.sstatic.net/OIZik.png html: <div class="messages"> <span class="c ...

Automatically change and submit an <input> value using jQuery

I have been working on a prototype to enable users to access all the data associated with a visualization. The idea is that they would click on a specific point, triggering a modal to appear, and within that modal, a table would dynamically filter based on ...

Tips for designing a fixed footer that remains visible at all times

I'm having trouble creating a sticky footer that stays visible regardless of how far the user scrolls on my page. I want it to look like the version on the left, but I'm getting something different on the right Here is the CSS I'm using: ...

"Adjust the width of a div element based on the unique ID of a

I am attempting to replicate a div multiple times, with each row in the database table creating a new instance. An example of what I'm aiming for is shown below. <?php for ($i=0; $i < 3; $i++) { ?><!-- replace '3' w ...

Is it possible to ensure that a newly created element functions in the same way as an existing element?

I am currently in the process of developing an application that empowers users to generate new items, modify existing items, or delete items by utilizing corresponding icons located adjacent to each item. When it comes to existing items, the action icon d ...

Increase the space below the footer on the Facebook page to allow for an

I recently created a webpage at and noticed that it is adding extra height below the footer on my Facebook page: "" I am seeking assistance on how to remove this additional 21px height below all content in the footer. I have tried various templates but n ...

When I attempt to press the shift + tab keys together, Shiftkey is activated

Shiftkey occurs when attempting to press the shift + tab keys simultaneously $("#buttonZZ").on("keydown",function (eve) { if (eve.keyCode == 9 && eve.shiftKey) { eve.preventDefault(); $("#cancelbtn").focus(); } if (eve. ...

Form with missing input fields submits nothing to the server

I created a Node project with a single view page for users to access information. When I use an HTML form to send data, the content is empty. I have verified multiple times using Postman that the information is being saved successfully when sent with the P ...

Strange gap between element and border on chrome

I noticed some strange spacing between the div borders and elements when I wrapped a few divs inside a container. This issue is only happening on Chrome and Edge, while Mozilla seems to display it correctly. My code includes the usage of Bootstrap along w ...

What could be causing the issue with ng-include not functioning properly?

Issue with ng-include Organized Directory Structure : ssh_project --public ----templates ------header.html ------footer.html ----views ------index.html Here is the content of my index.html file <body> <h1>Hello</h1> <div ng ...

Centered Bootstrap 4 modal with responsive width

Struggling to create a BootStrap 4 Modal that is centered in the screen and adjusts its width based on content? You're not alone. Despite trying different approaches like the container fluid and CSS methods, achieving a variable width modal is proving ...

Why does my anchor disappear after a second when clicked to show the image?

Hi everyone, I'm having an issue with a dropdown menu that I created using ul and anchor tags. When I click on one of the options, an image is supposed to appear. However, the problem is that the image shows up for just a second and then disappears. I ...

Update the sum upon deleting a feature in an HTML and JavaScript form

Once a row or field is added, this function will display a delete link. When clicked, it will remove the row or field: var ct = 1; function addNewRow(){ ct++; var divElement = document.createElement('div'); divElement.id = ct; // Code to cr ...

Tips for resolving encoding problems without the need to rewrite the content

Issue at Hand: When I copy a gridview from one .aspx page to another, I encounter a problem with Arabic words like: رقم اذن الإضافة They appear as: &#1585;&#1602;&#1605; &#1575;&#1584;&#1606; &#1575;&#1604;& ...