Dynamic horizontal div elements laid out in a repeating pattern using CSS Grid

I'm fairly new to CSS/Html/JS and I'd like to create a row of Boxes (loaded from a json file) displayed horizontally. Something similar to this:

Here's the code snippet I've been using:

<style> 
.wrapper {
    display: grid;
    grid-template-columns: auto auto;
}

.Product {
    display: grid;
    grid-template-columns: auto 1fr;
    background-color: rgb(2, 121, 61);
    padding: 10px;
}

</style>
<div class"Wrapper">
    <div class="Product">
        <div>Pos: </div><div id="pos">test1</div>
        <div>Artikel: </div><div id="article">test2</div>
        <div>Bezeichnung: </div><div id="name">test3</div>
        <div>Menge: </div><div id="stock">test4</div>
        <div>Einheit:</div><div id="einheit">test5</div>
        <div>Lagerplatz:</div><div id="shelf">test6</div>
        <div>Intern:</div><div id="barcode">test7</div>
    </div>

    <div class="Product">
        <div>Pos: </div><div id="pos">test1</div>
        <div>Artikel: </div><div id="article">test2</div>
        <div>Bezeichnung: </div><div id="name">test3</div>
        <div>Menge: </div><div id="stock">test4</div>
        <div>Einheit:</div><div id="einheit">test5</div>
        <div>Lagerplatz:</div><div id="shelf">test6</div>
        <div>Intern:</div><div id="barcode">test7</div>
    </div>
</div>

The current result looks like this:

As you can see, the divs are not aligned horizontally and the width extends past the screen. Ideally, I want the boxes to be horizontally aligned and not limited by the screen width. If it's possible to place the entire element in a horizontal scroll view, that would make me even happier. Thank you for your time.

Answer №1

For your product category, implement the use of inline-grid...

.wrapper {
    display: grid;
    grid-template-columns: auto auto;
}

.Product {
    display: inline-grid;
    grid-template-columns: auto 1fr;
    background-color: rgb(2, 121, 61);
    padding: 10px;
}
<div class"Wrapper">
    <div class="Product">
        <div>Pos: </div><div id="pos">test1</div>
        <div>Artikel: </div><div id="article">test2</div>
        <div>Bezeichnung: </div><div id="name">test3</div>
        <div>Menge: </div><div id="stock">test4</div>
        <div>Einheit:</div><div id="einheit">test5</div>
        <div>Lagerplatz:</div><div id="shelf">test6</div>
        <div>Intern:</div><div id="barcode">test7</div>
    </div>

    <div class="Product">
        <div>Pos: </div><div id="pos">test1</div>
        <div>Artikel: </div><div id="article">test2</div>
        <div>Bezeichnung: </div><div id="name">test3</div>
        <div>Menge: </div><div id="stock">test4</div>
        <div>Einheit:</div><div id="einheit">test5</div>
        <div>Lagerplatz:</div><div id="shelf">test6</div>
        <div>Intern:</div><div id="barcode">test7</div>
    </div>
</div>

Answer №2

It appears that the wrapper class was incorrectly specified. To ensure proper styling, it is recommended to use wrapper instead of Wrapper within the main div class. Additionally, if you desire spacing between columns, the grid-column-gap: 20px; property can be utilized.

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

Transforming Google Maps from using jQuery to AngularJS

If I have a Jquery google map with find address and routing system, my goal is to convert it to an angular google map with more options. The current Jquery google map code looks like this: var directionsDisplay = new google.maps.DirectionsRenderer({ d ...

Creating a fixed footer within a div that is absolutely positioned using CSS

I am looking to implement a sticky footer within an absolutely positioned div element. My initial approach was to position the footer div absolutely as well - within an additional relatively positioned "page" div (which would contain the main content of t ...

Is it possible to replicate an HTML table using JavaScript without including the headers?

Discover a JavaScript snippet in this stack overflow post that allows you to create a button for automatically selecting and copying a table to the clipboard. When pasting the data into an Excel template, my users prefer not to include the header informat ...

Tips for creating multiple popups using a single line of JavaScript code

I am new to JavaScript and I am attempting to create a popup. However, I am facing an issue in opening two divs with a single line of JavaScript code. Only one div opens while the other remains closed despite trying various solutions found on this website. ...

How to change the background color of a slider using jQuery

As a newcomer to web programming, I am currently working on incorporating a slider into my website using jQuery. My goal is to change the background color of the slider to red when the value is less than 5 and green when it exceeds 5. Can this be achieved ...

Is there a way to remove CSS based on the generated HTML code?

Currently tackling a project in Next.js involving custom SCSS, Bootstrap SCSS, and React-Bootstrap. Struggling with the bloated size of our main.scss file due to unused CSS. After observing that 95% of the CSS is not utilized, I aim to eliminate all unnec ...

What is the best way to retrieve the background color of specific table cells?

I have a table that showcases various pieces of information. One interesting feature I added is a notes column, which includes a tooltip created using CSS and jQuery. However, there seems to be an issue with the tooltip's behavior - when I hover over ...

fullPage.js with linear scroll

Is there a way to implement fullpage.JS without any transitions between slides? I attempted the following setup, but it didn't work as expected: $('#fullpage').fullpage({ licenseKey: 'XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX', ...

interactive navigation menu with countdown feature

Looking to create an HTML/jQuery dropdown menu, but encountering a problem. The goal is for the div to slide down when the mouse hovers over the "games" navigation button and only disappear after 5 seconds of the mouse being out, not instantly. Here's ...

Step-by-step guide on aligning an image to the left of text in a Material UI table column

After experimenting with inline styling, I attempted to move the images next to the text in a specific column. However, there are some rows where the images overlap or the text is positioned too far to the right, as shown in this image: https://i.stack.im ...

Excessive Expansion of Website Width

Initially, I crafted a website on my local server, and it had the ideal width. Afterwards, I uploaded it to the live server and made some design modifications. To my surprise, there is now an unexpected scroll bar at the bottom of the page, causing the s ...

In the event of a 404 error, simply direct the user to the pageNotFound before ultimately guiding them back

I'm developing a website with Node JS and I want to implement a feature where if the user attempts to navigate to a non-existent page, they are redirected to a "Page Not Found" message before being automatically taken back to the home page after a few ...

Tips for concealing an entire row of a table with Jquery

I am currently working on a system that involves a table with anchor tags named original and copy in each row. By clicking on these anchor tags, we are able to update the database whether the item is an original or a copy using ajax. However, I am facing a ...

Using Semantic-UI causes issues with the functionality of the height property set to 100%

View my CodePen here <head> <meta charset="utf-8"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.css"> </head> <body> <div class="ui secondary pointing menu" id=" ...

Hovering over an image will not cause the floating header to appear

My attempt to create a header that fades with scroll and appears on hover is working perfectly, except for the cat pictures in the Portfolio section. Despite adjusting z-indexes and trying various solutions, the header just won't show up over the h4 e ...

Executing PHP code upon clicking an HTML button

I am currently in the process of creating a simple webpage that will execute a stress test and mimic a load on my web server. The PHP code for stress is functioning properly, however, when I attempt to click the button, nothing seems to happen. <?php ...

mandating the selection of checkboxes

Currently, I am exploring the possibility of automatically selecting a checkbox when an option is chosen from a dropdown menu. Below is a code snippet that demonstrates what I am aiming to tweak: $('.stackoverflow').on('change', func ...

A guide to creating gradient borders using CSS

Does anyone have advice on applying a gradient to a border in CSS? I attempted using the following code: border-color: -moz-linear-gradient(top, #555555, #111111); Unfortunately, it did not work as expected. Can someone share the correct method for creat ...

Looking to validate each input field individually using jQuery?

I am in need of validating all form inputs in the keyup function without having to write validation for each individual input. Is there a way to achieve this using methods like each();? Apologies for what may seem like a silly question. ' ...

The icon cannot be displayed using the <use> tag in HTML

While examining the source code, I stumbled upon the <use></use> tag. <use xlink:href="#icon-ghost"></use> I couldn't find extensive information about this particular tag. Can someone explain what it is and how it is typicall ...