CSS | Creating gaps between elements within a form

My form is currently inside a flexbox card with two sides - left and right. The left side displays a picture, while the right side contains the actual input fields. I'm looking to add more space between the different inputs as they feel too cramped at the moment. I've attempted using flexbox properties like justify-content: space-around and space-between, but neither yielded the desired results.

I've also experimented with adding margin and padding to both the form and its elements, but I believe there must be a more effective solution out there. To provide better context, I have attached an image along with the JSFiddle link for reference.

@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

body {
    margin: 0;
    padding: 0;
    font-family: Roboto;
    font-size: 0.9em;
    background-color: #ccf2f4;
}

img {
    width: 200px;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.card {
    width: 75vw;
    margin: 10px;
    background-color: #a4ebf3;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
}

.card-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
}

.card-left,
.card-right {
    padding: 10%;
}
<div class="card">
    <div class="card-left">
        <img src="https://media.bleacherreport.com/f_auto,w_800,h_533,q_auto,c_fill/br-img-slides/004/431/800/ca7761a4360ae26cb69ee014607228b7_crop_exact.jpg" alt="" />
    </div>
    <div class="card-right">
        <form action="">
            <div class="name">
                <label for="name" placeholder="Name">Name</label>
                <input type="text" id="name" required />
            </div>
            <div class="seat">
                <label for="seat">Select your seat</label>
                <select name="seat" id="seat">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select>
            </div>
            <div class="handicapped">
                <label for="handicap">Handicapped?</label>
                <input type="checkbox" value="Handicapped" />
            </div>
            <div class="wrestler">
                <label for="wrestler">Select for favorite superstar</label>
                <select name="wrestler" id="wrestler">
                    <option value="asaka">Asaka</option>
                    <option value="mcintyre">Drew Mcintyre</option>
                    <option value="zayne">Sami Zayne</option>
                    <option value="reigns">Roman Reigns</option>
                    <option value="flair">Charlotte Flair</option>
                </select>
            </div>
            <div class="submit">
                <button>Sign Up!</button>
            </div>
        </form>
    </div>
</div>

While my primary expertise lies in JavaScript, I've been actively working on projects to enhance my CSS skills and expand my knowledge base. Your assistance and time are greatly appreciated. You can view a screenshot here.

Answer №1

If you're looking to create some space between your input elements, a simple CSS tweak can do the trick:

.card-right div{
  margin-bottom: 10px;
}

This adjustment will work well because each input element is already contained within its own div.

@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
body {
  margin: 0;
  padding: 0;
  font-family: Roboto;
  font-size: .9em;
  background-color: #ccf2f4;
}

img {
  width: 200px;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card {
  width: 75vw;
  margin: 10px;
  background-color: #a4ebf3;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
}

.card-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

.card-right div {
  margin-bottom: 10px;
}

.card-left,
.card-right {
  padding: 10%;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Simple Form Demo</title>
</head>

<body>
  <div class="container">
    <h1>Wrestlemania 36 Sign Up!</h1>
    <h2>Use the form below to reserve your spot for the year's biggest event</h2>
    <div class="card">
      <div class="card-left">
        <img src="https://media.bleacherreport.com/f_auto,w_800,h_533,q_auto,c_fill/br-img-slides/004/431/800/ca7761a4360ae26cb69ee014607228b7_crop_exact.jpg" alt="">
      </div>
      <div class="card-right">
        <form action="">
          <div class="name">
            <label for="name" placeholder='Name'>Name</label>
            <input type="text" id='name' required>
          </div>
          <div class="seat">
            <label for="seat">Select your seat</label>
            <select name="seat" id="seat">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
            </select>

          </div>
          <div class="handicapped">
            <label for="handicap">Handicapped?</label>
            <input type="checkbox" value='Handicapped'>
          </div>
          <div class="wrestler">
            <label for="wrestler">Select for favorite superstar</label>
            <select name="wrestler" id="wrestler">
              <option value="asaka">Asaka</option>
              <option value="mcintyre">Drew Mcintyre</option>
              <option value="zayne">Sami Zayne</option>
              <option value="reigns">Roman Reigns</option>
              <option value="flair">Charlotte Flair</option>
            </select>
          </div>
          <div class="submit">
            <button>Sign Up!</button>
          </div>
        </form>
      </div>
    </div>

  </div>

</body>

</html>

To see this in action, check out this helpful example on JSFiddle.

Answer №2

.card-right div {
    margin: 0 15px;
}

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

Step-by-step guide on aligning a div of unknown height in the center of a div with a set

Struggling to center product images vertically within a fixed height box? Here's the code I've been working with: <div class="main-pic"> <ul> <li><img src="images/extra/laptop.jpg"></li> <li><img ...

Executing jQuery AJAX with PHP using 'POST' method to receive and process PHP code

Something seems to have gone wrong with my setup; it was functioning properly before but is now encountering issues. When trying to make a POST call from an HTML file to a php file (which fetches data from a REST API), instead of receiving the expected API ...

bootstrap used for creating horizontal radio buttons

I'm attempting to horizontally align radio buttons within a form without relying on the Bootstrap library. The following code achieves this: <form id="test_form"> <div class="control-group"> <label for="Q1">First question</ ...

Create an HTML button on the homepage that directs users to the "about" page

I've been struggling to make a button in my Ionic app navigate to a different page upon clicking. Despite being new to Ionic, I've spent hours trying to solve this issue. Below is the HTML code in home.page.html: <ion-header> &l ...

The popover seems to be failing to appear

I am struggling to get a popover to appear when clicking on an appended href element dynamically. Here are the code snippets I have tried: <div id="myPopoverContent"> ...stuff... </div> <div id="div3" style= "width:200px;height:200px;" ...

I want to know how to showcase elements from a list one by one and cycle through them using a button with a nodejs server and Pug

As someone who is brand new to Web development, NodeJs servers, and Pug, this is my first time diving into any of these technologies. My goal is to create a dynamic box (in the form of a div) that changes its content based on a list from a JSON file. Initi ...

Bootstrap 4 - DropDown option - Element is positioned above the navigation bar

Currently facing an issue with the DropDown menu. Whenever I add padding to the DropDown menu (class - drop_link), it ends up pushing the entire element over the <nav>. I'm unsure of how to prevent this from occurring. I attempted to disable som ...

Opening the Gmail app from a link using JavaScript

What is the best way to open the Gmail app from a hyperlink? This link opens WhatsApp <a href="https://wa.me/">whatsapp</a> <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a1f190f ...

Troubleshooting issues with cloning a row using jquery

I'm having trouble figuring out why my code isn't working. I want to duplicate a div and add it to the beginning of its parent div. Here's the code I have so far: //Adding a new row function addRow(btn) { var CopiedRow = $(this).closest( ...

Adjust the span's width to make it shift position

Currently, I am in the process of learning HTML and there is a specific question that has come up for me. Within my <div class="input-group">, there are three elements: one span, one input field, and another span: <span class="input-group-addon q ...

Could you please guide me on resolving the Blazor/Bootstrap 5 CSS problem related to styling "striped" tables?

Looking for a solution to fix a CSS issue involving Bootstrap 5 "table-striped" and displaying Blazor Razor components. In my Blazor/Bootstrap 5 page, I have a table displaying content fetched from a service at runtime. Initially, the Bootstrap CSS is vis ...

developing both vertical and horizontal 'cross out'

I'm attempting to add a 'spacer' between buttons on my website using the word "or" with a vertical line centered above and below it. I've tried HTML <div class="footer-btn-wrap"> <div class="decor"><a href="... < ...

Locate an original identifier using Selenium WebDriver

In search of a distinctive identifier for the "update profile picture button" on my Facebook account to utilize it in automation testing with Selenium WebDriver and Java. I attempted driver.findElement(By.className("_156p")).click();, but unfortunately, i ...

Utilizing Ant Design Icons without an Internet Connection

In my current project, a reactJS application utilizing ant design for the UI was recently deployed to production on locked down computers. These computers lack internet access, causing ant design icons on modals to appear as empty boxes. Upon investigation ...

JavaScript: Understanding the concept of closure variables

I am currently working on an HTML/JavaScript program that involves running two counters. The issue I am facing is with the reset counter functionality. The 'initCounter' method initializes two counters with a given initial value. Pressing the &a ...

Implementing Materialize CSS functionality for deleting chips

I've been attempting to extract the tag of a deleted chip from the div within the Materialize chips class, but I'm hitting roadblocks. My failed attempts so far: $('.chips').on('chip.delete', function(e, chip){ console.lo ...

What is the proper way to leverage the global 'window' object within Angular?

I'm attempting to utilize the method "window["initMapCallback"]" to invoke and monitor for "initMapCallback" in a separate file. However, I am encountering an error message in the debugging console that states Query - How can I properly implement thi ...

Changing the description doesn't affect the fixed height of the box - here's how to do it with CSS

Here are the references I used: GetBootstrap Jumbotron CoreUI Base Jumbotron This is how my script looks like: <template> <div class="wrapper"> <div class="animated fadeIn"> <b-card> <b-row v-for="row in ...

Achieving vertical alignment and stretching of subchild within a flexbox element

I am in the process of creating a mobile navigation menu using Flexbox. It will be a vertical menu that occupies 100% of the available height, with the navigation items evenly spaced and taking up the entire height. The structure I am using is ul>li> ...

Incorporating jQuery to seamlessly add elements without causing any disruptions to the layout

I'm looking to enhance the design of my website by adding a mouseenter function to display two lines when hovering over an item. However, I've encountered an issue where the appearance and disappearance of these lines cause the list items to move ...