Form layout disrupted by grid template areas

I'm in the process of creating a contact form for my website. I've utilized grid-template-areas to organize the form input fields. However, upon adding the grid area to the form input, all the form fields disappear except for the last one. Could someone please advise me on what I might be doing incorrectly?

Does anyone have any suggestions?

#home-f .contact-wrapper {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: (1fr)[2];
      grid-template-columns: repeat(2, 1fr);
  grid-gap: 2rem;
}

#home-f .contact-text p {
  width: 90%;
  font-size: 1rem;
  margin: 1rem 0;
}

#home-f .contact-form {
  display: -ms-grid;
  display: grid;
      grid-template-areas: 'name email'
 'service'
 'message';
  grid-gap: 1.2rem;
}

#home-f .contact-form #name {
  -ms-grid-row: 1;
  -ms-grid-column: 1;
  grid-area: name;
}

#home-f .contact-form #email {
  -ms-grid-row: 1;
  -ms-grid-column: 2;
  grid-area: email;
}

#home-f .contact-form #service {
  -ms-grid-row: 2;
  -ms-grid-column: 1;
  grid-area: service;
}

#home-f .contact-form #message {
  -ms-grid-row: 3;
  -ms-grid-column: 1;
  grid-area: message;
}
    <section id="home-f" class="py-4">
      <div class="container">
        <div class="contact-wrapper">
          <div class="contact-text">
            <h2 class="m-heading">How May We Help You!</h2>
            <p>
              Grursus mal suada faci lisis Lorem ipsum consectetur elit. Grursus
              mal suada faci lisis Lorem ipsum consectetur elit.
            </p>
            <form action="">
              <div class="contact-form">
                <input
                  type="text"
                  name="name"
                  placeholder="Your Name *"
                  id="name"
                  class="form-control"
                />
                <input
                  type="text"
                  name="email"
                  placeholder="Email Address *"
                  id="email"
                  class="form-control"
                />
                <select name="service" id="service" class="form-control">
                  <option value="">Select a service...</option>
                  <option value="website-development">
                    Website Development
                  </option>
                  <option value="speed-optimization">Speed Optimization</option>
                  <option value="lead-generation">Lead Generation</option>
                  <option value="video-editing">
                    Video Editing / Voice over
                  </option>
                  <option value="graphics">Graphics & Design</option>
                  <option value="other">Other</option>
                </select>
                <textarea
                  name="message"
                  placeholder="Your Message"
                  id="message"
                  class="form-control"
                ></textarea>
              </div>
            </form>
          </div>
          <div class="contact-img">
            <img src="assets/img/contact.png" alt="" />
          </div>
        </div>
      </div>
    </section>

Answer №1

The issue arises due to the structure of your grid with two columns. When defining the grid-template-areas for your child elements, you have not assigned grid-area names for the second column. The current setup looks like this:

grid-template-areas: 'name email'
'service service'
'message message';

To leave the second column empty, you need to use . to fill the spaces.

#home-f .contact-wrapper {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: (1fr)[2];
      grid-template-columns: repeat(2, 1fr);
  grid-gap: 2rem;
}

#home-f .contact-text p {
  width: 90%;
  font-size: 1rem;
  margin: 1rem 0;
}

#home-f .contact-form {
  display: -ms-grid;
  display: grid;
      grid-template-areas: 'name email'
 'service service'
 'message message';
  grid-gap: 1.2rem;
}

#home-f .contact-form #name {
  -ms-grid-row: 1;
  -ms-grid-column: 1;
  grid-area: name;
}

#home-f .contact-form #email {
  -ms-grid-row: 1;
  -ms-grid-column: 2;
  grid-area: email;
}

#home-f .contact-form #service {
  -ms-grid-row: 2;
  -ms-grid-column: 1;
  grid-area: service;
}

#home-f .contact-form #message {
  -ms-grid-row: 3;
  -ms-grid-column: 1;
  grid-area: message;
}
<section id="home-f" class="py-4">
      <div class="container">
        <div class="contact-wrapper">
          <div class="contact-text">
            <h2 class="m-heading">How Can We Assist You?</h2>
            <p>
              Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
              tempor felis nec quam sagittis, a vulputate libero accumsan.
            </p>
            <form action="">
              <div class="contact-form">
                <input
                  type="text"
                  name="name"
                  placeholder="Your Name *"
                  id="name"
                  class="form-control"
                />
                <input
                  type="text"
                  name="email"
                  placeholder="Email Address *"
                  id="email"
                  class="form-control"
                />
                <select name="service" id="service" class="form-control">
                  <option value="">Select a service...</option>
                  <option value="website-development">
                    Website Development
                  </option>
                  <option value="speed-optimization">Speed Optimization</option>
                  <option value="lead-generation">Lead Generation</option>
                  <option value="video-editing">
                    Video Editing / Voice over
                  </option>
                  <option value="graphics">Graphics & Design</option>
                  <option value="other">Other</option>
                </select>
                <textarea
                  name="message"
                  placeholder="Your Message"
                  id="message"
                  class="form-control"
                ></textarea>
              </div>
            </form>
          </div>
          <div class="contact-img">
            <img src="assets/img/contact.png" alt="" />
          </div>
        </div>
      </div>
    </section>

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

Meta tag settings for iOS web applications fail to function

I am currently working on a website locally using a MAMP stack. One issue I am facing is that none of the necessary meta tags for configuring a website as an iOS standalone web application seem to be working in my header, which is wrapped in a php template ...

The flipping action will only occur on the initial card

I am working on creating a unique photo gallery that allows users to flip the picture by clicking or tapping on it. Once flipped, users will be presented with additional information about the image and a link. I have included all of my CSS, JS, and HTML be ...

Disable the display of meridian in the UI Bootstrap datetime picker

Currently, I am utilizing the ui-bootstrap-datetime-picker with angularJS. I am wondering if it is feasible to directly set the show-meridian options of the time-picker inside the timepickerOptions. ... <input type="text" class="form-control" ...

How to deactivate user controls on a Google Maps embed

I am attempting to incorporate a basic Google map into my website using the embed feature available on maps.google.com. Below is the generated code: <iframe src="https://www.google.com/maps/embed?pb=!1m12!1m8!1m3!1d2391.716465442018!2d-0.6309220000000 ...

How to create list item bullets with a star icon using reactstrap/react?

As a machine learning professional looking to enhance my frontend skills, I am curious about how to create list item bullets using a custom star bullet image. Could anyone please share a complete HTML/CSS example with me? Thank you in advance! ...

What's the best way to align text in relation to the image?

enter image description here I need help with positioning my text relative to the resizing image at different breakpoints. Can anyone assist with this? Is there a way to position text relative to the background in a manner that it always stays attached t ...

Tips for effectively implementing grids within bootstrap modal dialogs?

Exploring the functionality of the bootstrap-5 grid system within a modal popup has raised a puzzling issue. To investigate further, I began by incorporating the grid example into the main modal template sourced from https://getbootstrap.com/docs/5.0/compo ...

A guide to mastering the art of descending using three distinct class types

My script is functioning properly for a single class, but it fails to work for multiple classes with the same purpose. I attempted to transfer from div (#panel) to class (.panel) as I am using several classes. However, this adjustment did not resolve the i ...

Customize the appearance of the search box in Serverside Datatables

Is there a way to adjust the search and show inputs for datatables so that I can customize their width and make them fit my dynamic column sizing? The issue I ran into is that these inputs are enclosed within <label> tags in the source JavaScript, an ...

What is causing my AJAX script to refresh the page repeatedly?

I am currently testing the functionality of submitting a form using ajax. The script I have in place is designed to echo some plain text in processform.php. However, when I click on the submit button, no alert is displayed and the page is reloaded instead. ...

Implementing an active class to an element based on the current URL using Jquery in Django

Is there a way to dynamically add an "active" class to an element based on the href? This is what my template in Django looks like: <div class="panel side-panel-1 category"> <h4 class="title1">Sections</h4> <ul class="clear-list"> ...

I recently implemented a delete function in my code that successfully removes a row, but now I am looking to also delete the corresponding data from localStorage in JavaScript

I have successfully implemented a delete function in JavaScript that deletes rows, but I also want to remove the data from local storage. This way, when a user reloads the page, the deleted row will not appear. The goal is to delete the data from local s ...

Instructions for implementing personalized horizontal and vertical scrolling within Angular 9

I am currently working on an angular application where users can upload files, and I display the contents of the file on the user interface. These files may be quite long, so I would need vertical scrolling to navigate through them easily. Additionally, fo ...

What is the best way to extract plain text with JQuery?

I found this Html code snippet: <div class="form-group row"> <label id="lb_size" class="col-lg-3 col-form-label"> <span class="must-have">****</span> Size </label> </div> My goal is to ext ...

Employ a for loop to generate custom shapes within the canvas

EDIT: I will be sharing all of my code including the HTML and JS. Pardon me for the abundance of comments. I am attempting to generate rectangles in a canvas using a for loop (taking user input) and then access them in another function to perform certain ...

What could be causing my navbar to not be responsive on mobile devices?

I'm in need of assistance. When viewing my website in mobile mode, the collapse hamburger menu is hiding too far to the right. This issue is making the site look unresponsive, and I've been unable to find a solution. It seems like the problem sta ...

Can anyone explain the strange hexagonal substance that appeared in my POST to an InMagic Textworks system?

Upon reviewing the POST request details on an Inmagic TextWorks system in Chrome developer tools, I discovered the following while delving into the POST: Form Data view source URL encoded status: mode:sort currentPage:1 querySql:[PROCESSED]c:5f:2:61:58:-6 ...

The navigation/hamburger icon vanishes after a click on a page link

I'm in the process of creating a single-page scrolling website. However, I am encountering an issue with the navigation bar. Specifically, when I click on a page link from the nav bar at screen widths less than 780px (when the hamburger icon appears), ...

How to fetch select element within a table by using jQuery

I encountered a situation where I have a table element with a select element inside its td. The id of the table (in this example, it is "table1") could potentially change. So my query is, how can I retrieve the selected option using the table ID in JQuer ...

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 ...