Creating a flexible grid with varying numbers of columns using HTML and CSS

My Razor page currently showcases a series of thumbnail images stacked in a vertical position:

@foreach (var photo in Model)
{
    <div>@photo.PhotoId</div>
    <div>@photo.Title</div>
    <div>
        <img src="@photo.LargeSquareThumbnailUrl" alt="Many cups!" />
    </div>
}

I am eager to rearrange these images horizontally on a single row. In the case that there is an overflow issue, I would like to implement a horizontal scrollbar.

While I understand that CSS may help with handling overflow, I am struggling to determine how to initially stack the images in a row. Any guidance or suggestions would be greatly appreciated!

Answer №1

The best approach would be to use a container with white-space:nowrap and make each pod an inline block:

.container {
  white-space: nowrap;
  overflow: auto;
  max-width: 100%;
}

.wrapper {
  display: inline-block;
  white-space: normal;
}
<div class="container">
  <div class="wrapper">
    <div>@photo.PhotoId</div>
    <div>@photo.Title</div>
    <div>
      <img src="http://via.placeholder.com/150x150" alt="Many cups!" />
    </div>
  </div>
  <div class="wrapper">
    <div>@photo.PhotoId</div>
    <div>@photo.Title</div>
    <div>
      <img src="http://via.placeholder.com/150x150" alt="Many cups!" />
    </div>
  </div>
  ...
  </div>

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

experimenting with adding fresh choices to dropdown menu using ajax and jquery

When attempting to load a list of locations through ajax/jQuery, I encounter an issue. After typing a letter into the input field, the first response is displayed but subsequent responses are simply appended to it. I have tried using .html('') an ...

What is the process for inserting an SVG object into an HTML document?

Currently, I am experimenting with d3.js examples to create visual graphs. Here is the link for reference. Below is the snippet where I've implemented the LineChart function to construct the graph, with Django as the backend. {% load static %} < ...

arrange object array in descending order based on an object's numerical value within it (using Angular-Typescript)

Looking for assistance with sorting an array of user objects based on their scores. Each user object contains properties like userId, userName, and score. My goal is to create a leaderboard where the user with the highest score appears at the top, followed ...

What is the best method to create a gap between the header and table body in Angular Material version 13?

Is there a way to create space (margin) between the header and body in an Angular Material table? I initially attempted to use a solution found here, but it was unsuccessful. Check out the demo here: https://stackblitz.com/edit/angular-ivy-anphrw?file=sr ...

What could be causing my canvas to not display my sprite?

Currently, I am in the process of learning JavaScript and experimenting with creating games to make the learning experience more enjoyable. However, I am facing an issue while using EaselJS and CreateJS to develop these games as a beginner. I need some as ...

Flexbox: Distribute remaining space evenly while allowing content to wrap

Is there a method to instruct flexbox items to occupy the available space while wrapping as soon as they become smaller than their content? However, some items have a fixed width percentage. HTML <div class="grid"> <div class="grid__item"> ...

Is there a way to retrieve the immediate children of all elements using CSS selectors in Selenium?

Although I attempted to utilize the ">" syntax, selenium does not seem to accept it. I am aware that Xpath can be used to obtain what I need, however our project exclusively utilizes CSS selectors. My goal is to create a list containing only the immedi ...

What is the best way to target a specific class to exclude in CSS styling?

Here is the css code snippet: .single-post .container { width: 60%; } not(.single-post) .container{ min-width:92%; } The goal I am aiming for is to have the container width set to 60% on single post pages and 92% on all other pages. T ...

Working with a complex JSON structure in JavaScript exemplifies the use of loops

I am currently utilizing json.data.schedules[0].liveVideoList, json.data.schedules[1].liveVideoList, json.data.schedules[2].liveVideoList and so forth. Can someone please guide me on how to implement a loop to retrieve all paths? Here is the code in scri ...

Experiencing an issue with the left side menu bar in Bootstrap, looking to incorporate additional sub menu items

<li class="drop-menu-tab"> <a class="dropmenu" ><i class="icon-folder-close-alt"></i><span> Employee</span></a> <ul> <li><a class="submenu&q ...

Text obstructed by a sticky sidebar in Bootstrap

Currently, I am utilizing bootstrap to create a webpage featuring an affixed sidebar. However, I have encountered two issues when adjusting the screen size to that of a phone: The sidebar obstructs the text behind it, halting its movement beneath the sid ...

Can you provide an explanation for the "ved" parameter used in a Google search?

I've been spending a good couple of hours trying to unravel the mystery behind the "ved" parameter in Google search results. Curiosity always gets the best of me. Here's what I've discovered so far: The value of "ved" changes- 1 - for ever ...

Save hyperlinks provided by users within the text

Users have the ability to create a post and leave a comment. I am aiming to give my users the option to include a hyperlink in their comment, such as: "This is a comment where aboutme is a hyperlink." I am unsure of how to store this hyperlink. Currently, ...

A unique way to present data: An HTML table featuring four fixed columns with horizontal scrolling

I've been having difficulty creating a table with fixed first four columns while allowing the rest to scroll horizontally. I came across this example first column fixed Although the example has the first column fixed, I'm struggling to extend it ...

Discover the steps to trigger a Bootstrap popup modal when clicking on an anchor link using Angular

I have an Angular application and I would like to display a Bootstrap popup modal when the user clicks on a link in the footer. Here is the Bootstrap modal code: <button type="button" class="btn btn-primary" data-toggle="modal&q ...

The central navigation system of the Owl Carousel

I am currently using the owl carousel plugin and I am struggling to figure out how to center align the navigation vertically while also using the autoHeight option. http://codepen.io/anon/pen/jJAHL I have attempted the following code snippet, but it seem ...

Deploying static files with Django in a production environment

My Django application is functioning properly on Ubuntu 14.04 with nginx 1.10, Django 1.10.2, and uWSGI 2.0.14. It is able to load static files such as JavaScript, CSS, and images, but the CSS files are not being applied to my website. Below is the configu ...

Responsive div that reacts to scrolling

I am looking for a div that can dynamically change its position as I scroll up or down the page. For example, it could start 30px from the top but then move to 100px as I scroll down further. This div will be located on the right-hand side of my page, clo ...

My dilemma lies in attempting to display a <div> when I hover over a different <a> element. What could be causing this issue?

I have tried numerous solutions to this issue on the website and have incorporated the recommended techniques, but I still can't figure out what's missing. Could it be a larger code structure that is hindering my progress or am I simply overlooki ...

What is the best way to place content in a single div without it being divided into several separate boxes

Here is my code snippet: <div class="col-md-9"> <div id="statbox"> {% for obj in product_type %} {% for obj1 in vastu %} <script type="text/javascript"&g ...