Information arranged in a matrix

Hey everyone, I have all these input boxes and I want to organize them in a 3x4 or 4x3 grid layout instead of having them stacked on top of each other. I've tried using grid and other code but it just doesn't seem to work. Do you have any suggestions on how to solve this? Keep in mind that this is for a chrome extension popup so there may be limitations due to the maximum width.

html {
  background-color: #d63031
}

input {
  border: white solid;
  background: #;
  -webkit-border-radius: 7px;
  -moz-border-radius: 7px;
  border-radius: 7px;
  color: #574026;
  -webkit-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  -moz-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
}
<html>

<head>

  <script src="script.js"></script>
</head>

<body style="width:600px">
  <p>Text</p>
  <p style="font-size:smaller"><em>Text</em></p>
  /* Additional input fields go here */
  
  <p><input style="background-color:#6c5ce7;border:none;" type="submit" id="send"></p>
</body>

</html>

Answer №1

For grids to function properly, it is not necessary to have maximum width. Below is a functional solution, although your desired outcome was not explicitly stated. Please inform me if I have overlooked any details.

To create a grid system, you must have a container and place the input boxes you wish to group within a div, as shown below:

<div id="grid">
    <div id="grid-1">
        <p>Name: <input placeholder="Name and Surname" id="name"></p>
        <p>Email: <input placeholder="Email" id="email"></p>
        <p>Telephone: <input placeholder="Telephone" id="phone"></p>
    </div>
    <div id="grid-2">
        <p>Address: <input placeholder="Address" id="address"></p>
        <p>City: <input placeholder="City" id="city"></p>
        <p>Postal Code: <input placeholder="Postal Code" id="postcode"></p>
    </div>
    <div id="grid-3">
        <p>Card Number: <input placeholder="Card Number" id="cardnumb"></p>
        <p>Country Code: <input placeholder="IT,UK,..." id="country"></p>
        <p>Card Type: <input placeholder="american_express, master, visa, solo, paypal" id="cardtype"></p>
    </div>
    <div id="grid-4">
        <p>Expiration Month: <input placeholder="01,02,03,04,05,06,07,08,09,10,11,12" id="month"></p>
        <p>Expiration Year: <input placeholder="2018,2019..." id="year"></p>
        <p>CVV: <input id="cvv"></p>
    </div>
</div>

On the CSS side, specify a display grid for the container and indicate the column in which each div containing the input boxes should be placed.

#grid {
    display: grid;
    grid-gap: 20px;
}

#grid-1 {
    grid-column: 1/2;
}

#grid-2 {
    grid-column: 2/3;
}

#grid-3 {
    grid-column: 3/4;
}

#grid-4 {
    grid-column: 4/5;
}

This arrangement will neatly group and align all your input boxes side by side. I hope this explanation proves helpful :)

Answer №2

It seems like there might be some confusion in your question, but one solution could be to utilize flexbox. Keeping your existing code as is, you can wrap your inputs in a div with a class of .input-group.

I would also suggest adding labels to your inputs and changing the use of <p> to <div>

html {
  background-color: #d63031
}

body{
  width: 600px;
}

.input-group{
  display: flex;
  display: -webkit-box; 
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex; 
}

.input-group p{
  width: 33.3%;
  padding: 0 10px;
}

.input-group input{
  width: 100%;
}

input {
  display: block;
  border: white solid;
  background: #;
  -webkit-border-radius: 7px;
  -moz-border-radius: 7px;
  border-radius: 7px;
  color: #574026;
  -webkit-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  -moz-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
}

  <p>Text</p>
  <p style="font-size:smaller"><em>Text</em></p>
  <div class="input-group">
    <p>Nome: <input placeholder="Name and Surname" id="nome"></p>
    <p>mail: <input placeholder="Email" id="mail"></p>
    <p>tel: <input placeholder="Telephone" id="tel"></p>
  </div>
  <div class="input-group">
    <p>addr: <input placeholder="Address" id="indirizzo"></p>
    <p>City: <input placeholder="City" id="citta"></p>
    <p>PostCod: <input placeholder="PosteCode" id="pc"></p>
  </div>
  <div class="input-group">
    <p>CardNumber: <input placeholder="Card Number" id="provola"></p>
    <p>CountryCode <input placeholder="IT,UK,...." id="paese"></p>
    <p>Card Type <input placeholder="american_express, master, visa, solo, paypal" id="tipo"></p>
  </div>
  <div class="input-group">
    <p>ExpirationMonth: <input placeholder="01,02,03,04,05,06,07,08,09,10,11,12" id="mese"></p>
    <p>ExpirationYear: <input placeholder="2018,2019..." id="anno"></p>
    <p>Cvv: <input id="cvv"></p>
  </div>



  <p><input style="background-color:#6c5ce7;border:none;" type="submit" id="send"></p>

Answer №3

After analyzing the provided CSS, it can be determined that the first column will have a fixed width of 200px while the second column will take up 1fr (“one fraction”) of the remaining available space.

html {
  background-color: #d63031
}
body{display: grid;
grid-template-columns: 200px 1fr;}

input {
  border: white solid;
  background: #;
  -webkit-border-radius: 7px;
  -moz-border-radius: 7px;
  border-radius: 7px;
  color: #574026;
  -webkit-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  -moz-box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
  box-shadow: rgba(255, 255, 255, 0.4) 0 1px 0, inset rgba(000, 000, 000, 0.7) 0 0px 0px;
}
<html>

<head>

  <script src="script.js"></script>
</head>

<body style="width:600px">
  <p>Text</p>
  <p style="font-size:smaller"><em>Text</em></p>
  <p>Nome: <input placeholder="Name and Surname" id="nome"></p>
  <p>mail: <input placeholder="Email" id="mail"></p>
  <p>tel: <input placeholder="Telephone" id="tel"></p>
  <p>addr: <input placeholder="Address" id="indirizzo"></p>
  <p>City: <input placeholder="City" id="citta"></p>
  <p>PostCod: <input placeholder="PosteCode" id="pc"></p>

  <p>CardNumber: <input placeholder="Card Number" id="provola"></p>
  <p>CountryCode <input placeholder="IT,UK,...." id="paese"></p>
  <p>Card Type <input placeholder="american_express, master, visa, solo, paypal" id="tipo"></p>
  <p>ExpirationMonth: <input placeholder="01,02,03,04,05,06,07,08,09,10,11,12" id="mese"></p>
  <p>ExpirationYear: <input placeholder="2018,2019..." id="anno"></p>
  <p>Cvv: <input id="cvv"></p>



  <p><input style="background-color:#6c5ce7;border:none;" type="submit" id="send"></p>
</body>

</html>

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

Retrieve information from ngResource (angularjs) based on the chosen item

I am currently developing a small application that needs to display a list of cities only when a country is selected using ngResource in angularjs. The problem I am facing is that the entire list of countries and cities is being rendered initially, causing ...

Prevent the table cell width from expanding beyond the content size

Is there a way to achieve this layout without relying on Javascript? Imagine having a <table> with an unknown width in the first column. The overall <table> width is set to 100% to allow other columns to resize accordingly, but is it possible ...

Automatically adjust the top margin of the content section to accommodate a fixed header height

After extensive searching, I've come across various solutions but none of them seem to fit my needs. I am a beginner/amateur developer. The issue I am facing is with a fixed header that resizes when scrolling. I understand that by adding padding-top: ...

Crafting a personalized arrow for sorting headers in Angular Material

Currently working on an Angular 5 project and I'm looking to implement a custom sort icon in the header. The goal is to achieve a similar effect to this example, without using the default arrow. I attempted to modify the CSS styles, but it wasn' ...

Having trouble with jQuery div height expansion not functioning properly?

Having a bit of trouble with my jQuery. Trying to make a div element expand in height but can't seem to get it right. Here's the script I'm using: <script> $('.button').click(function(){ $('#footer_container').anim ...

spaces between sections with no padding or borders

I came across the following layout on the web and noticed that the divs do not align perfectly. The top of a lower div does not touch the bottom of the div above it when borders are removed, although they do when borders are added. There seems to be an i ...

Troubleshooting Angular modal fade not functioning

I am facing an issue while trying to display a component called "Login", which belongs to the class "modal fade", from another component named "navbar". Despite my attempts to trigger it by calling data-bs-toggle="modal" data-bs-target="#LoginModal" from t ...

Arrange 4 divs (children) at each corner of the parent element

Currently, I am facing a challenge in positioning 4 divs in the corners of their parent div. The HTML code structure is as follows: <div class="resize"> <div class="n w res"></div> <div class="n e res"></div> < ...

The separator falls short of spanning the entire width of the page

For some reason, I can't seem to make the divider extend to the full length of the page. <TableRow> <TableCell className={classes.tableCell} colSpan={6}> <Box display="grid" gridTemplateColumn ...

HTMLMediaElement does not have the setSinkId method

I am currently in the process of developing a WebRTC application using Angular, with the goal of managing audio output through the setSinkId() method within HTMLMediaElement. However, when attempting to use this method, I am encountering an error message s ...

JavaScript code that allows users to select text on a website

As I work on developing a chrome extension, my goal is to allow users to select text. I successfully achieved this by running the code in the chrome console. document.onselectstart=new Function ("return true"); However, when I attempted to incorporate th ...

It appears that the font in style.css is not being updated properly and seems to resemble

My issue lies within my CSS code. The text on my website is not displaying correctly and seems to be ignoring the styling that I have applied. Even though I have used similar styling on other buttons which look fine, this specific text element is causing p ...

Utilize Bootstrap 4 to create a full screen desktop layout with columns that automatically adjust to

I am struggling to create a full-screen layout using Bootstrap 4, similar to the one shown in this image. I'm facing issues with the left and right columns not taking up the remaining space between the navigation and footer sections. Additionally, I n ...

There seems to be a limitation in JS/JQuery where it is unable to append HTML that spans

I am encountering an issue with retrieving data in a div element. It seems that the function provided does not work correctly for files larger than a single line of code or even possibly a string. What can be done to resolve this? <ul class="dropdo ...

Generating SVG images that show up as black in light mode and switch to light colors in dark mode

I am currently working on a website that has the option to switch between light and dark mode, and I need my logo to adjust accordingly. The black elements of my logo should appear black in dark mode and light in light mode. I attempted using the CSS cod ...

What is the best way to add a button over an image using Tailwind CSS in Next.js?

I've been trying to display a button on top of an image using Tailwind CSS and Next.js, but I'm having trouble getting it to align properly. Here is the code snippet I've been working with: <div> <Image src={projectAiWrite ...

Why does React-Perfect-Scrollbar not work properly when the height of an element is not specified in pixels?

Currently, I am developing a chat application with React 18 for its user interface. The app includes a sidebar that displays user profiles. To ensure the app fits within the browser window height, I've made the list of user profiles scrollable when n ...

Locate the class identifier within the source SCSS document that is condensed into a unified CSS file when rendered in the browser

In the application I'm working on, the index.html file uses app.css, which is generated from multiple SCSS files. When inspecting an element to find its corresponding CSS, is there a way to determine which SCSS file that style originated from? ...

Canvas flood fill is having trouble reaching the edges

While utilizing a flood fill algorithm to fill circles drawn on the canvas, I've encountered an issue where the algorithm fails to fill right up to the edge of the circle. Here is the implementation of the algorithm based on this blog post: function ...

Secret message concealed within the depths of my Bootstrap 5 Side Navbar

I have successfully created a side NavBar using Bootstrap 5, but I'm facing an issue where my text is getting hidden behind the navbar. Any suggestions on how I can resolve this? Below is the code for my side Navbar: const Navbar = ({ handleClick, is ...