Use flexbox to arrange labels and input fields in a single line for better display

I've been working on a project where I need to lay out labels and input fields on separate lines using flexbox.

            <form  class="form">
              <label> Credit Card Number </label>
              <input type="search" name="creditcard" placeholder="4831-0948-9417-4341">

              <label>Date</label>
              <input type="date" name="date">

              <label for="cvc">Cvc</label>
              <input type="text" name="cvc" placeholder="809">

            <label for="postcode">Zip</label>
            <input type="number" name="postcode" placeholder="94100">

              <input type="submit" value="Search">
            </form>

http://codepen.io/o-sewell/pen/egPGYm?editors=1100

Answer №1

Did you mean something like this?

      .label {
        display: block;
      }

      .form {
        display: flex;
      }

      .cell{
        float: left;
      }
<form  class="form">
  <div class="cell">
    <label> Credit Card Number </label></br>
    <input type="search" name="creditcard" placeholder="4831-0948-9417-4341">
  </div>
  <div class="cell">
    <label>Date</label></br>
    <input type="date" name="date">
  </div>
  <div class="cell">
    <label for="cvc">Cvc</label></br>
    <input type="text" name="cvc" placeholder="809">
  </div>
  <div class="cell">
    <label for="postcode">Zip</label></br>
    <input type="number" name="postcode" placeholder="94100">
  </div>
  <div class="cell">
    <input type="submit" value="Search">
  </div>
</form>

Answer №2

Thanks for your help, I believe I have figured it out based on your response.

<form  class="form">
              <div class="cell">
              <label> Credit Card Number </label>
              <input type="search" name="creditcard" placeholder="4831-0948-9417-4341">
              </div>
              <div class="cell">
              <label>Date</label>
              <input type="date" name="date">
              </div>
              <div class="cell">
              <label for="cvc">Cvc</label>
              <input type="text" name="cvc" placeholder="809">
              </div>
              <div class="cell">
              <label for="postcode">Zip</label>
              <input type="number" name="postcode" placeholder="94100">
              </div>
              <input type="submit" value="Search">
            </form>


    form {
      display: flex;
    }

    .cell {
      display: flex;
      flex-direction: column;
      flex: 1;
    }

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

JavaScript: Issue with triggering form submit event

I'm facing an issue with getting the submit event to trigger on my form. I've added a submit button to the form and have included a script at the end of the body that references the necessary JavaScript functions for the form, but it's still ...

The canvas is either displayed solely on the first image of the slider or attached to the bottom of every image

While attempting to implement a feature where clicking on an image would draw a circle on a canvas overlaying it, I encountered an issue. When applying cnvs.style.position = 'absolute';, all canvas elements stack on top of each other instead of b ...

Generating an interactive tooltip for an image using a click event (html, scss)

I have a social media icon with a click-through URL. When someone hovers over the icon, I would like a sentence to be displayed over it (a tooltip). Using the "title" command is doing the job, but I can't style it as needed. I believe using an inline ...

The CSS styling in Internet Explorer 11 is causing cells to merge into the same column in a table

In my CSS-styled form that resembles a table, the two input elements are displaying on top of each other instead of side by side. How can I adjust them to appear next to each other? There is a possibility that this issue could be browser-specific. The for ...

Using regular expressions to extract URLs from code in Python

My research involves a dataset of newspaper article links, but I've run into an issue. The links in the dataset all end with .ece extension, which is causing problems due to some API restrictions. http://www.telegraaf.nl/telesport/voetbal/buitenlands ...

Tips for preventing browsers from losing style information stored in inputs

https://i.sstatic.net/ab9nF.jpg My custom input field has unique CSS styles applied to it, but unfortunately, when the browser auto-fills the information in those fields, the styles get reset. ...

How can we prevent having an abundance of jQuery confirmation dialog boxes and instead focus on reusing them

I'm currently updating an old web application using jQuery. Within the form, there are 40 buttons that trigger a confirmation prompt using javascript confirm. I aim to replace these with jquery modal dialogues. While I've successfully implement ...

Leveraging the power of HTML validation while silencing the constant flood of messages

I want to keep the HTML validation in place but disable only the error message that prompts users to fill out required fields. Users should still not be able to submit the form without filling in a text field, but I don't want the standard "Please fil ...

Active State of Menu Items

I have been struggling with a problem all day and can't seem to find a solution. I have searched the internet thoroughly, but haven't found any helpful resources. There are similar questions out there, but none of them have provided me with the ...

Tips for embedding HTML/CSS snippets in backticks when using TypeScript with AngularJS

Does anyone else experience the issue of their Angular 2 templates showing up as gray text in Visual Studio Code? I'm unable to use autocomplete or see my CSS properly. Is this a settings problem or is there a plugin that can solve this? BTW, I am us ...

Bootstrap Modals Fail to Appear

Encountering an issue where the modal fails to display upon successful saving of data in the database. The data is successfully saved, but the ModalSuccess does not appear. This data originates from a form passed into AJAX. In case no input is provided in ...

Displaying iFrame Border in React Native WebView

When attempting to dynamically add YouTube videos to my React Native app, I decided to utilize a combination of WebView and iFrame due to the incompatibility of the current react-native-youtube component with RN 16+. Although this solution works, the ifram ...

The pagination feature for Swiper is experiencing issues across both desktop and mobile platforms

I am having an issue with the pagination display in the text. I would like it to appear below the text as a standalone item for better visibility. Another problem arises when viewing the page on mobile devices - the hamburger menu displays behind the slid ...

Expand the <div> to match the complete height of its containing <div> element

There are multiple div blocks within a parent block: one for the menu on the left, and one for the text on the right. How can you make the right inner block stretch to the full height of the parent block like the left one? The parent block has a minimum he ...

Simple method to incorporate a CSS border, shadow effect, and rounded edges to enhance my content

My website, , is running smoothly. I have noticed that on larger monitors, the animation on the sides of the pages could be enhanced if my main content had a red/black border with rounded corners and possibly a drop shadow. I am searching for the simples ...

What is the best way to insert content using AJAX into a Twitter Bootstrap modal dialog box?

Currently, I am working with Zend Framework 2 and have been following a helpful tutorial on integrating form submission via AJAX. Instead of utilizing a jQuery UI modal, I have opted to use the modal provided by Twitter Bootstrap 3. My initial goal is to ...

A guide on effectively selecting an element with the '@font-face' tag

I'm endeavoring to design a distinctive logo by utilizing a personalized font... and am keen on incorporating it into my CSS As an illustration: the identifier for my div element is "logo" Should I merely employ this code? #logo { font-family: ...

Vue.js transition-group does not apply the *-move class

As I dive into learning Vue, I find myself wondering if I may have overlooked something fundamental or stumbled upon a bug. Despite multiple readings of the documentation at https://v2.vuejs.org/v2/guide/transitions.html#List-Move-Transitions, I still can& ...

"Using HTML to assign a unique identifier to an image within

Apologies in advance for any errors as I am relatively new to html. I am attempting to construct a table with images that have onclick events, so that each clicked seat is tracked and its id is added to a list to change the class. Each image has been give ...

Utilizing CSS Media Queries for Page Layout Adaptation

After previously asking about a different issue with this project, I have encountered yet another problem. The task at hand requires using three distinct media queries to alter the page layout depending on the screen size in use (currently being tested by ...