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:

https://i.sstatic.net/ZgxMR.png

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:

https://i.sstatic.net/iu16r.png

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

Show the saved email message text on an HTML webpage

Is there a way to show the email content stored in a HTML page? $.ajax({ type: "POST", url: "./mailBody.php", dataType: 'json', success: function (data) { $.each(data, function(index, element) { $('.mail ...

Creating elegant Select Dropdown Box in AngularJS without relying on images

I am currently working on an angular page and have implemented a dropdown with ng-Options to fetch and set values successfully. However, I am now looking to enhance the appearance of this dropdown. After exploring options like ui-select, I realized that be ...

The outcome of data binding is the creation of a connected data object

I am attempting to link the rows' data to my view. Here is the backend code I am using: [Route("GetCarCount")] [HttpGet] public async Task<long> Count() { return await _context.Cars.CountAsync(); } ...

Fine-tuning the flexbox grid layout for various screen sizes, both big and small

Two different layouts were created. The first layout is designed for medium & large screens, while the second one is tailored for devices with a maximum width of 736px. Check out the vanilla implementation using flexbox (without mobile adaptation) Here ...

"What is the purpose of using the `position: absolute` property for movement transitions while deleting an item from a list

Click here to see an example where items smoothly move in a list when one item is removed. To achieve this effect, the element needs to be styled with: .list-complete-leave-active { position: absolute; } I'm curious as to why it doesn't work w ...

checkbox-activated navigation bar

Struggling to implement a Nav-drawer that should open when a checkbox is selected, everything seems to be set up correctly but the issue arises when it comes to actually opening it. Here is the code snippet: <div class="leftside"> <input typ ...

Issue with form validation, code malfunctioning

I am struggling to figure out why this validation isn't working. Here is the HTML code I'm using: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type='text/javascript' src="scripts. ...

Creating a compilation of HTML file links using Gulp

Is there a way to utilize Gulp in order to compile a single HTML file containing links to all pages within a specific directory? For instance, if I have two files contact.html titled "Contacts" and faq.html titled "Frequently asked questions" located in t ...

Internet Explorer 9 (IE9) causing CSS dropdown menu to be truncated due

My issue is very similar to the problem described in this post: CSS Flyout menu gets cut off by borders of its container in IE9 The difference in my case is that I need to set the z-index (and position) on the container. You can view my JSFiddle here: h ...

Encountering a problem with quintus-all.js and need assistance

I am having an issue with my animation code. Can someone help me troubleshoot it? window.addEventListener('load', function(){ var Q =window.Q= Quintus().include("Sprites, Scenes,2D, Anim").setup({maximize:true}); Q.Sprite.extend(&apos ...

Tips on customizing the selected icon color in Material-UI's BottomNavigationAction styling

I'm facing an issue with Material-UI styled components and could use some assistance. My goal is to create a BottomNavigation bar in React using Material-UI v5 where the selected option's icon displays in red (#f00) while the unselected icons sho ...

A method for merging the values of three text fields and submitting them to a hidden text field

<label class="textRight label95 select205">Cost Center: </label> <input type="hidden" name="label_0" value="Cost Center" /> <input type="text" name="value_0" class="input64 inputTxtGray" value="" maxlength="10" /> <input type=" ...

Applying flexbox to create a visually appealing design

Is there a way to achieve this layout using flexbox without relying on grid due to limited support in IE11? I want to be able to easily add or remove small divs without adding more containers. To see the desired layout, check out this image: Desired Layou ...

I'm encountering an issue with my CSS image slider as it does not seem to be functioning properly on Google Chrome, yet

CSS: @-moz-keyframes slidy { 0% { left: 0%; } 20% { left: 0%; } 25% { left: -100%; } 45% { left: -100%; } 50% { left: -200%; } 70% { left: -200%; } 75% { left: -300%; } 90% { left: -300%; } 95% { left: -400%; } 10 ...

Angular template not refreshing automatically

Within my controller: $scope.deleteUser = function(user){ $.ajax({ url: "/users/" + user.id.toString(), method: "DELETE", success: function(result){ $scope.users = result["users"]; ...

encountering issues while attempting to create personalized profile pages with dynamic content

I'm currently working on creating a dynamic profile page that can be accessed by everyone using the link www.example.com/user/$id. Currently, the profile pages are not public and cannot be viewed by other users. I attempted to add the following code ...

Using jQuery to retrieve the domain extension from a URL

Seeking assistance with extracting domain extensions from various URLs using jQuery. Uncertain how to account for all possible scenarios. Here are the parts of the URL that need to be extracted: https://www.amazon.**com**/dp/067144901X https://www.amazon. ...

Disregard validation of the view if the element includes the attributes `display: none`

Displayed below is an HTML text input that is designed to toggle visibility using jQuery's slideUp and slideDown functions, which change the display attribute to none with animation. My current challenge is that I do not want to validate the element w ...

Implementing grid items in CSS Grid that do not stretch the grid row and have a container that is scrollable

Here is my dilemma: I am looking to create a grid with a fixed number of columns (that can be adjusted via javascript) and a variable number of rows, all with equal heights. The rows will be determined by the number of grid items, which are represented a ...

The col-md-4 class in Bootstrap does not consistently maintain a width of 33%

Currently, I am utilizing bootstrap cards in my project. The number of cards within a card-deck varies dynamically. However, I have encountered an issue where each card should occupy a width of col-md-4 (33%). Everything works fine when there are more than ...