placing additional containers at the bottom rather than on the right side

Hey there! I'm currently working on a simple website and I'm having trouble getting the duplicated form rows to appear aligned below the previous one. Here's what I have right now:

var i = 0;
var original = document.getElementById("duplicater");

function duplicate() {
  var clone = original.cloneNode(true);
  clone.id = "duplicater" + ++i;
  original.parentNode.appendChild(clone);
}
h1 {
  text-align: center;
}

h3 {
  text-align: center;
  color: red;
  font-size: 13;
}

.grid-container-1 {
  display: grid;
  max-width: 480px;
  grid-auto-columns: repeat(3, 1fr);
  grid-template-areas: "nuevo content .";
}

.ProdRow {
  display: grid;
  max-width: 480px;
  grid-area: content;
  grid-auto-columns: repeat(3, 1fr);
  grid-template-areas: "code desc date";
  position: relative;
  float: down;
}

.selector {
  border-radius: 4px;
  margin-bottom: 10px;
  padding: 0 5px;
  width: 150px;
  background-color: #ebebeb;
  position: relative;
}

.selector label {
  font-size: 10px;
  text-transform: upper;
  color: #777;
  padding: 2px 8px 0;
  position: relative;
  top: 6px;
}

.New-item {
  grid-area: nuevo;
}

.ProdRow #ItemCode {
  grid-area: code;
}

.ProdRow #Desc {
  grid-area: desc;
}

.ProdRow #FechaReq {
  grid-area: date;
}
<main id="main">
  <H1 id="titulo">Portal de solicitud de compra</h1>

  <div class="grid-container-1">
    <div class="New-item">
      <button id="NewBTN" onclick="duplicate()">Nuevo</button>
    </div>

    <div class="ProdRow" id="duplicater">
      <div class="selector" id="ItemCode">
        <Label id="etItCode">Código de producto</label>
        <select>
          <option>1</option>
          <option>222222</option>
        </select>
      </div>

      <div class="selector" id="Desc">
        <label id="etDesc">Descripción de producto</label>
        <select>
          <option>Lorem ipsum</option>
        </select>
      </div>

      <div class="selector" id="FechaReq">
        <label id="etFecha">Fecha requerida</label>
        <input type="date" id="fechareq" name="FechaReq">
      </div>

    </div>

  </div>

  <h3> If you can't find the product, request its creation and try again.</h3>
</main>

In essence, I'm attempting to duplicate the rows of the form to add more items while keeping them aligned. I've experimented with various CSS properties like float, relative positioning, and max-width but none seem to be effective so far.

I appreciate any help or suggestions you can provide. Thank you in advance!

Answer №1

Your JavaScript code is perfectly fine, the issue lies within the CSS.

I made a change in your CSS by removing the line display: grid; from the .grid-container-1 selector, which resolved the problem of the duplicated form appearing below the original one.

To fix this issue, ensure that your CSS for the .grid-container-1 selector looks like this:

.grid-container-1 {
    max-width: 480px;
    grid-auto-columns: repeat(3, 1fr);
    grid-template-areas: "nuevo content .";
}

Answer №2

document.querySelector('button#NewBTN').onclick = function(e){
    var parent = e.target.parentElement;
      var innerElement = `<div class="selector" id="ItemCode">
              <Label id="etItCode">Product Code</label>
              <select>
                <option>1</option>
                <option>222222</option>
              </select>
            </div>
            <div class="selector" id="Desc">
              <label id="etDesc">Product Description</label>
              <select>
                <option>Lorem ipsum</option>
              </select>
            </div>
            <div class="selector" id="FechaReq">
              <label id="etFecha">Required Date</label>
              <input type="date" id="fechareq" name="FechaReq">
            </div>`;
      var div = document.createElement('div');
      div.classList.add('ProdRow');
      div.innerHTML = innerElement;
      parent.appendChild(div)
      //console.log(parent.innerHTML)
}
h1 {
  text-align: center;
}

h3 {
  text-align: center;
  color: red;
  font-size: 13;
}

.grid-container-1 {
  display:flex;
  flex-direction:column;
}

.New-item > button{
  margin-bottom:10px;
  padding: 6px 10px;
  background: coral;
  color: #fff;
  border-color: coral;
  border-radius: 4px;
}

.New-item > button:focus,
.ProdRow select,
.ProdRow input{
  outline:none;
}

.ProdRow {
  display:flex;justify-content:space-between;
  background-color: #ebebeb;
  padding: 10px;
  margin-bottom:5px;

}

.selector {
  border-radius: 4px;
  margin-bottom: 10px;
  padding: 0 5px;
  width: 150px;
  position: relative;
}

.selector label {
  font-size: 10px;
  text-transform: upper;
  color: #444;
  margin: 0 0 5px;
  position: relative;
}

.ProdRow select,
.ProdRow input{
  padding:6px 10px;
  border-radius:4px;
  border:1px solid #999;
}
<main id="main">
  <H1 id="titulo">Purchase Request Portal</h1>

  <div class="grid-container-1">
    <div class="New-item">
      <button id="NewBTN">New</button>
    </div>

    <div class="ProdRow">
      <div class="selector" id="ItemCode">
        <Label id="etItCode">Product Code</label>
        <select>
          <option>1</option>
          <option>222222</option>
        </select>
      </div>

      <div class="selector" id="Desc">
        <label id="etDesc">Product Description</label>
        <select>
          <option>Lorem ipsum</option>
        </select>
      </div>

      <div class="selector" id="FechaReq">
        <label id="etFecha">Required Date</label>
        <input type="date" id="fechareq" name="FechaReq">
      </div>
    </div>
  </div>

  <h3> If the product is not found, request its creation and try again.</h3>
</main>

Give this solution a try to address your issue and share your feedback.

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

Programmatically adjusting the color of mask images - Creative image theming

Is it possible to alter the color of an image hosted on a different website? Here is a link to an example image: Is there a technique to overlay a specific color on the image and only modify certain colors, such as changing or adding a layer of light gre ...

issue with using references to manipulate the DOM of a video element in fullscreen mode

My current objective is to detect when my video tag enters fullscreen mode so I can modify attributes of that specific video ID or reference. Despite trying various methods, I have managed to log the element using my current approach. Earlier attempts with ...

What is the method for generating an oval shape with a border-radius in CSS?

Is there a way to create an oval shape instead of a rectangle with rounded edges using CSS? Below is the code snippet I have been working with: div { position: fixed; border-radius: 25px; background: rgba(0,0,0,.5) width: 100px; height: 50px; ...

What is the best way to interpret HTML special characters (such as those with accents) in a Facebook share post?

<meta property="og:title" content="<?php echo $title; /> where $title is retrieved from a database. The title should display as blácv with the character a accented, but when sharing the post on Facebook, it appears as bl&aacutecv. T ...

What is the best way to extract value from a specific link using JavaScript?

I have a PHP script that retrieves data from a database: <?php while($trackResultRow = mysqli_fetch_assoc($trackResult)){?> <a onclick="remove()"><span class="glyphicon glyphicon-thumbs-down pull-right"></span></a> < ...

Looking for a way to locate words enclosed in square brackets and change them into dynamic URLs using PHP?

In my quest to locate words enclosed in square brackets, such as [word], and form a dynamic URL, I encountered a challenge. Although I attempted using the str_replace() function to identify the word, it resulted in generating links in this format: <a ...

Fetch information from the input field and send it to the Redux state

Looking for a solution - I'm working on a simple todo app where I need to store user input value in the redux state. The input value is currently stored in local state until the user clicks the "add" button. The main issue : How can I pass this input ...

Is there a way to showcase the uploaded file contents on the current page without the need to refresh?

Is there a way to display the contents of an uploaded file on the same HTML page without opening a new tab or refreshing it? I have the following HTML and PHP codes for reading an uploaded file in a separate page, but I want to integrate it into the same H ...

Is there a way to modify the color of the horizontal line within react-native-otp-inputs in the React Native platform?

Is there a way to customize the color of the horizontal line in react-native-otp-inputs for react native? I used react-native-otp-inputs to capture user OTP input, but now I want to change the color of the default black horizontal line to white. You can re ...

`Prepare and load all materials in advance`

Question: On my page, I have a slideshow displaying images and videos. Before starting the slideshow, I want to ensure that all content on the page has loaded. Does $(window).load() verify if all content, including videos, has been loaded? Thanks in adv ...

Tips for resolving the issue of dropdown menus not closing when clicking outside of them

I am currently working on an angular 5 project where the homepage consists of several components. One of the components, navbarComponent, includes a dropdown list feature. I want this dropdown list to automatically close when clicked outside of it. Here i ...

Issue with HTML form not correctly submitting AJAX request to controller

My attempt to utilize ajax on the add to cart form doesn't seem to be working as expected. When I click on the Add to Cart button, it displays a blank page because I have implemented an ajax check method in the controller. Controller public functio ...

The step-by-step guide to testing an Angular promise using Jasmine

An issue arises when attempting to test the code below using Jasmine, as the console.log in `then` is never called. The question remains: is this problem related to Angular or Jasmine? describe("angular test", function() { var $q; ...

Load iframe once to display on multiple HTML pages

In my web application, I have implemented an iframe that is used on multiple pages. My goal is to load the iframe once on the login screen and have it remain static when navigating to subsequent pages, without refreshing. Is there a way to keep a specific ...

ASP.NET page experiences issues with executing Javascript or jQuery code

Having trouble with client scripts not functioning correctly on a child page that utilizes a master page. Looking for help to resolve this issue. <%@ Page Title="" Language="C#" MasterPageFile="~/Store.Master" AutoEventWireup="true" CodeBehind="NewSt ...

Unable to utilize Socket.io version 2.0.3

When it comes to developing a video chat app, I decided to utilize socket.io. In order to familiarize myself with this library, I followed various tutorials, but unfortunately, I always encountered the same issue. Every time I attempted to invoke the libr ...

Updating state array within reducer leads to duplicate execution of calculations

const updateCartReducer = (state, action)=>{ console.log('running the updater function') const existingItemIndex = state.items.findIndex( (item) => item.restaurant === action.item.restaurant && ...

As I iterate through a MySQL array, JavaScript is able to manipulate the initial displayed data

I'm struggling to achieve the desired outcome with my code. It seems that when I iterate through an array of data, JavaScript only works on the first echoed data. Here is a snippet of the code: <?php $ids = array(); ...

I am interested in modifying the destination of the screen transition depending on the numerical input provided in the form

I have recently started working on a project using Spring Boot, Thymeleaf, and MySQL. For instance, when the input form is submitted with the value "1" as the DB ID, I expect to be redirected to http://localhost:8080/edit/1. However, I am facing an issue ...

I am currently experiencing difficulties with uploading an image from the admin panel in Magento 1.9. Instead of receiving the expected response, I am

I encountered an error while trying to upload a file in Magento for a product image. When I click on upload, an error is displayed during the file upload process. Upon further investigation in the product.js file for item response, I noticed that HTML is b ...