show a pair of input buttons within a form

Seeking assistance with a contact form I created using bootstrap. The issue lies in the placement of the submit and clear buttons, which are currently stacked on top of each other instead of being displayed inline next to each other.

The form contents are formatted in table rows and columns, with contact labels in one column and form fields in another. The form is enclosed in a div with a bootstrap class of col-md-6 for 50% width of the page.

The problem arises from the buttons being placed under the first column of the table, occupying insufficient room. My query is how to display the two buttons next to each other across the full width of the form rather than the column width.

View the replicated code on jsfiddle: https://jsfiddle.net/neenus/nofuvqod/3/

#jumbotron-form {
  display: block;
  opacity: 0.90;
}

form {
  text-align: left;
  display: table;
  border-spacing: 0.25em;
}

.form-group {
  display: table-row;
}

label {
  display: table-cell;
  vertical-align: top;
}

input {
  display: inline;
}

textarea {
  width: 100%;
}
<div class="jumbotron" id="jumbotron-form">
  <div class="col-md-6">
    <form action="SUBMIT">
      <div class="form-group">
        <label for="name">Name: </label>
        <input type="text" name="name" id="name" placeholder="enter your name" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="tel">Telephone: </label>
        <input type="tel" name="tel" pattern="Telephone" id="tel" placeholder="(999) 999-9999" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="email">e-Mail: </label>
        <input type="email" name="email" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b252a262e0b2e262a222765282a">[email protected]</a>" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="usrmsg">Message: </label>
        <textarea name="message" id="usrmsg" cols="50" rows="5" placeholder="enter your message here..."></textarea>
      </div>
      <div>
        <input type="submit" value="Submit" id="submit">
        <input type="reset" value="Clear">
      </div>
    </form>
  </div>
</div>

Answer №1

Check out the following HTML5 & Bootstrap markup for your code....

/***********************************************************************************************/
/* Input Field   */
/***********************************************************************************************/
input[type="text"],
input[type="name"],
input[type="phone"],
input[type="email"],
textarea {
  border: none;
  padding: 8px;
  border-radius: 3px;
  width:100%;
  color: #454545;
  font-size: 16px;
  font-style: normal;
  background-color: #F5F5F5;
}

input[type="text"]:hover:focus,
input[type="name"]:hover:focus,
input[type="phone"]:hover:focus,
input[type="email"]:hover:focus,
textarea:hover:focus {
  padding: 8px;
  border-radius: 3px;
  min-width: 280px;
  font-style: normal;
  background: #F5F5F5;
}

/***********************************************************************************************/
/* Button & Reset  */
/***********************************************************************************************/
input[type="submit"],
input[type="reset"],
button {
  font-size: 16px;
  font-weight: 300;
  border: none;
  padding: 10px 30px;
  color: #ffffff;
  border-radius: 2px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  -moz-background-clip: padding;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  background-color: #2FB7D5;
  -moz-box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
  -webkit-box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
}

input[type="submit"]:hover,
input[type="reset"]:hover,
button:hover {
  font-size: 16px;
  font-weight: 300;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  -moz-background-clip: padding;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  background-color: #2FB7D5;
  -moz-box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
  -webkit-box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- ================================================
 Contact Form Start
================================================= -->

<section class="contact-form">
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<form action="" method="post" name="form" id="form">
<p>
<label for="name">Name</label>
<input type="text" name="" id="name" placeholder="Name" required>
</p>

<p>
<label for="email">Email</label>
<input type="email" name="email" id="email" placeholder="Email" required>
</p>

<p>
<label for="message">Message</label>
<textarea name="" id="message" cols="40" rows="5" placeholder="Write here..." required></textarea>
</p>

<input type="submit" value="Send">
<input type="reset" value="Write Again">
</form>
</div>
</div>
</div>
</section>

Answer №2

If you want to achieve this layout, you can utilize flex-box. I have made some updates to your code, please review the snippet and fiddle for reference.

#jumbotron-form {
  display: block;
  background-size: cover;
  opacity: 0.90;
}

form {
  text-align: left;
  display: table;
  border-spacing: 0.25em;
}

.form-group {
  display: table-row;
}

label {
  display: table-cell;
  vertical-align: top;
}

input {
  display: inline;
}

textarea {
  width: 100%;
}

.submit {
  display: flex;
}

.submit input {
  margin-right: 20px;
}
<div class="jumbotron" id="jumbotron-form">
  <div class="col-md-6">
    <form action="SUBMIT">
      <div class="form-group">
        <label for="name">Name: </label>
        <input type="text" name="name" id="name" placeholder="enter your name" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="tel">Telephone: </label>
        <input type="tel" name="tel" pattern="Telephone" id="tel" placeholder="(999) 999-9999" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="email">e-Mail: </label>
        <input type="email" name="email" id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9efbf3fff7f2defaf1f3fff7f0b0fdf1f3">[email protected]</a>" autocomplete="off">
      </div>
      <div class="form-group">
        <label for="usrmsg">Message: </label>
        <textarea name="message" id="usrmsg" cols="50" rows="5" placeholder="enter your message here..."></textarea>
      </div>
      <div class="submit">
        <input type="submit" value="Submit" id="submit">
        <input type="reset" value="Clear">
      </div>
    </form>
  </div>
</div>

Answer №3

Issue arises because of the use of display: table within the <form> tag. To resolve this, I made adjustments to your markup and CSS by introducing an additional <div> wrapper for all .form-group elements.

Take a look at the updated solution here: https://jsfiddle.net/nofuvqod/5/

Code Snippet:

#jumbotron-form {
  display: block;
  background-size: cover;
  opacity: 0.90;
}

form {
  text-align: left;
  border-spacing: 0.25em;
}

.form-table{
  display: table;
}

.form-group {
  display: table-row;
}

label {
  display: table-cell;
  vertical-align: top;
}

input {
  display: inline;
}

textarea {
  width: 100%;
}

HTML

<div class="jumbotron" id="jumbotron-form">
  <div class="col-md-6">
    <form action="SUBMIT">
      <div class="form-table">
        <div class="form-group">
          <label for="name">Name: </label>
          <input type="text" name="name" id="name" placeholder="Enter your name" autocomplete="off">
        </div>
        <div class="form-group">
          <label for="tel">Telephone: </label>
          <input type="tel" name="tel" pattern="Telephone" id="tel" placeholder="(999) 999-9999" autocomplete="off">
        </div>
        <div class="form-group">
          <label for="email">e-Mail: </label>
          <input type="email" name="email" id="email" placeholder="example@example.com" autocomplete="off">
        </div>
        <div class="form-group">
          <label for="usrmsg">Message: </label>
          <textarea name="message" id="usrmsg" cols="50" rows="5" placeholder="Enter your message here..."></textarea>
        </div>
      </div>

      <div>
        <input type="submit" value="Submit" id="submit">
        <input type="reset" value="Clear">
      </div>
    </form>
  </div>
</div>

Answer №4

To create a button group, utilize the container with the class form-group.

<div class="form-group">
  <input type="submit" value="Submit" id="submit">
  <input type="reset" value="Clear">
</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

Using Ajax to make a request on the same page but specifically within a column

I'm currently experimenting with AJAX to display live CSV data on my website. Right now, the AJAX script triggers on button click, but what I really want is for the data to be shown in a grid view without requiring a refresh or clicking a button. Howe ...

What is the method for displaying the delete icon, a child component located within the Menu Item, upon hovering over it using Material UI CSS syntax?

My goal is to display the delete icon when hovering over a specific menu item that is being mapped using the map function. The desired functionality is for the delete icon to appear on the corresponding menu item when it is hovered over. I attempted to i ...

Utilizing an array of font styles in a single line while maintaining a consistent width

I am creating a simple webpage with fixed width text. Check out this sample HTML: <div id ="wrap"> <h1>An Annoying Heading</h1> <p>Some text some text some text some text some text some text some text some text some text so ...

Pressing the button will add text into the input field

Below is a jsfiddle link showcasing the current issue I am trying to address: http://jsfiddle.net/YD6PL/61/ Here is the HTML code snippet: <input type="text> <input type="text> <input type="text> <div> <button class="buttons"& ...

Trigger a JavaScript function when a key is pressed down

Hey everyone, I'm trying to figure out how to trigger a JavaScript function when a particular key is pressed. For example, I want the function down() to be executed when the down key is pressed and function left() when the left key is pressed. Is ther ...

Exploring the process of passing parameters in Material-UI React styled components

Recently, I developed a new component const CategoryDialog = (props) => { const classes = useStyles(); console.log(props); return ( <div> <Dialog fullScreen open={props.dilaogOpenProp} TransitionCompone ...

Something strange happening with the HTML received after making a jQuery AJAX request

My PHP form handler script echoes out some HTML, which is called by my AJAX call. Below is the jQuery code for this AJAX call: $(function() { $('#file').bind("change", function() { var formData = new FormData(); //loop to add ...

Ways to gather all the elements on each page

Currently engrossed in a web scraping endeavor for a car website utilizing Selenium. One potential roadblock I've encountered is that the code seems to only iterate over the initial car element on the page, instead of going through the entirety of ava ...

Allow one child to be visible even if the parent container has hidden overflow (or a different setting)

Is there a way to achieve the same look as shown in this example, but without repeating the border-radius code for the div.left in the CSS? It feels redundant and I suspect my approach may not be optimal. If you have any suggestions on how to accomplish t ...

Disable the default form input reset button generated by Internet Explorer 10

Just have one field form for search input. Below is the HTML code: <form class = "search-form hide-on-mobile"> <input class = "global" type = "text" placeholder = "Who are you looking for ?"> <but ...

"Implementing a button in a flask data table: A step-by-step guide

Hello, I am facing an issue with adding a button to a Bootstrap datatable in Flask (Python) using JavaScript. Any tips or solutions would be greatly appreciated. I am trying to achieve something like this: https://i.sstatic.net/NtaB3.png I have attempted ...

What is the method to display a caret in regular HTML text with the use of JavaScript?

Currently, I am studying JavaScript and aiming to develop a typing game similar to typeracer.com. The goal of the game is to type accurately and quickly without errors. In this game, users input text into a box, and JavaScript then compares their inputs w ...

Issue with font-size changes using css variables in Angular not updating in browser for specific fields

Utilizing CSS variables, I have implemented a feature that allows users to adjust the font size to small, medium, or large. While this functionality works correctly for most fields, there are certain instances where the value is applied but not displayed. ...

Limiting the character input in ion-textarea within Ionic 2: A step-by-step guide

In my Ionic 2 application, I need to limit user comments to less than 500 characters in a text area. What is the best way to implement this restriction? ...

Is there a way to redirect focus to an object with a lower z-index when working on overlaying a sequence of transparent divs on a map?

Is it possible to give focus to a parent div that contains a child div without hiding the child div? I am integrating the Google Maps API and need to overlay a grid of transparent divs for inserting information. However, with these divs on top of my map, ...

Can WebGL be configured to render offscreen without its canvas being directly connected to the DOM?

Searching for an answer to what I believed would be a simple question has proven to be quite challenging. My goal is to utilize WebGL for image processing and generation tasks, with the intention of working offscreen. Specifically, I aim for WebGL to rende ...

Step-by-step guide on displaying a fresh page within a JavaScript code

I've been working with XHTML, JSF, and JavaScript to develop a form that validates user input in selected fields when a button is clicked. The goal is to redirect the user to a different page called homepage.xhtml after successful validation. However, ...

Combining 2 rows in an HTML table: A step-by-step guide

Can anyone help me figure out how to merge the first row and second row of a table in HTML? I have already merged two rows, but I am having trouble merging the first and second rows together. This is how I want my rows to be merged: |-------------------- ...

Evaluating the layout of a webpage with each new code update

I'm currently in search of a testing framework to evaluate the frontend and design aspects of my application. We are developing an Angular application and utilizing Protractor for end-to-end tests, but I am curious about how to test the visual design ...

What is the best way to position these two images side by side in a row?

Is there a way to place both images in the same row while also adding subtitles to each? I've tried different approaches, but I can't seem to align them properly with the subtitles included. <div class="container row-info"> <div cla ...