Using Foreach with Bootstrap to display a grid of 6 column items with images

When using a foreach loop to display clients with images, the desired layout is for them to be listed in 6 columns. For instance, if there are 18 clients, they should be displayed in a grid of 6 columns and 3 rows.

Here is the Razor code and HTML:

<div class="row">
@foreach (var patient in Model)
{
    <div class="col-xs-2">

        <figure style="text-align: center; margin-top: 10%; display: block;">

            <img src="~/Content/images/pdficon.png" alt="">

            <figcaption>
                <div style="margin-top: 5%"><h4>@(patient.Name)</h4></div>
            </figcaption>
        </figure>
    </div>
}

The current output can be seen in this sample image. While the 6 columns are displayed correctly, the alignment in rows seems to be off.

Answer №1

If you want to save time, consider inserting a break after every 6 patients.

@{int patientCount = 0};
@foreach (var patient in Model)
{
    <div class="col-xs-2">

        <figure style="text-align: center; margin-top: 10%; display: block;">

            <img src="~/Content/images/pdficon.png" alt="">

            <figcaption>
                <div style="margin-top: 5%"><h4>@(patient.Name)</h4></div>
            </figcaption>
        </figure>
    </div>
@{
if(patientCount % 6 == 0)
       @Html.Raw("<br/>");
   patientCount++;
}

}

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

Trouble with Angular and Bootstrap dropdown functionality

I recently upgraded to Angular 11 for my application https://i.sstatic.net/XrqIC.png and incorporated Bootstrap 4 with Angular. While all other Bootstrap components are functioning properly, the dropdown feature is not working as expected. Despite install ...

An ASMX web service encountering an unescaped double quote within a parameter while processing JSON data

Within my HTTP REQUEST, a valid JSON string is present with a double quote in the middle of the name "jo\"hn" escaped. This was captured by Fiddler Web Debugger. {"name":"firstName","value":"jo\"hn"}, It's important to note that the reques ...

Is it possible to incorporate WinForms into .NET Core?

I am in the process of developing a bot for a Discord server using Discord.NET, and I am interested in building a WinForm for this project rather than using a console. Is it possible to integrate WinForms into a .NET Core application? ...

Can Selenium successfully scrape data from this website?

I am currently attempting to extract Hate Symbol data (including the name, symbol type, description, ideology, location, and images) from the GPAHE website using Selenium. As one of my initial steps, I am trying to set the input_element to the XPATH of the ...

Do we really need to use Task.FromResult in this await statement?

A question has been on my mind since I started working on an existing project: Here is a piece of code snippet to consider: public async Task<IHttpActionResult> DoSomething(Guid token) { var data= await repository.GetDataAsync(token); return await ...

How can I find the last element that was selected using XPath in the browser console

Need help with XPath: $x(("//div[@class='ag-header-row']))[1] I'm working with an array of divs, but I want to select the last one. The [1] is necessary due to multiple rows with this class. I’ve heard about using [last()], but unsure w ...

Guide on creating a C# extension method with several arguments

Struggling with an extension method that only accepts one parameter. Here is the C# code snippet: public static string ToEncrypt(this string key, string passWord) { // Implementation code for encryption method } When trying to use this extension met ...

Guide to Setting the Color of a Link Using CSS

I’ve been attempting to change the color of an ALink using CSS, but it seems like I just can’t get it right. It’s clear that I’m missing something, as I’ve spent quite a bit of time tinkering with this seemingly simple issue and still can’t fi ...

HTML - Centered layout with a constant header and footer

Imagine a layout where there is always a header at the top, a footer at the bottom, and the space between them should be filled by the content 100% (image 2). Additionally, everything in the header, content, and footer should be horizontally centered, usin ...

Extracting Menu Information from Weedmaps

I've been attempting to extract menu data from dispensaries listed on weedmaps.com, but I'm struggling to understand how the website is structured and where the relevant information is located for scraping. My goal is simple: I want to retrieve ...

Determine the vertical distance that a div element is currently visible while scrolling

To better understand this concept, please refer to the following fiddle: http://jsfiddle.net/abhicodes/LasxP/ The main goal here is to calculate the visible height of the element with the ID #content-wrapper as the user scrolls. The height of the header ( ...

Tips for modifying a resource assembly within a C# .net program

Currently, I am working on modifying an existing string/icon resource assembly coded in C# in Visual Studio. I have researched various methods to edit the binary file directly, with the main tool being mono.cecil (http://www.mono-project.com/docs/tools+lib ...

Limit the ability to zoom in a webview application

I am facing an issue with my Android WebView app that is designed to load a specific URL and display it along with its links within the app. Despite setting the webpage size to 720px x 1280px using CSS to fit the screen of a Galaxy S3, I am encountering di ...

Executing a JavaScript function when a user releases the mouse after dragging an element using Jquery

Currently, I am utilizing JQuery UI to move div elements within a container and I am looking for a way to trigger an event when the user stops dragging them. If anyone has any suggestions on how to achieve this, I would greatly appreciate it. Thank you in ...

What is the best way to eliminate all borders from a select box?

Is there a way to completely remove all borders from the selectbox using either CSS or JQuery? The code snippet is as follows: <select id="doctor_ch"> <option value="1" selected>One</option> <option value="2">Two</option& ...

Having trouble accessing CSS images in JSF

Issue Details : I am currently facing a problem with setting menu background images in my JSF application using CSS properties. The file structure is as follows This is the CSS snippet Style.css #menu { height:35px; width:950px; backgrou ...

Adding text with jQuery

Currently, I am utilizing the Jquery text editor plugin known as JqueryTE. While adding some functions to it, I have encountered a roadblock. Specifically, I am attempting to insert additional text into the source of the textarea but have been unsuccessfu ...

Leveraging MEF for generating numerous iterations of a plugin

How can one efficiently generate multiple instances of an exported part within a MEF container when needed? Current implementation involves the use of MEF to compose components and load various plugins from a directory. The Container.Compose() method is u ...

Unable to choose multiple options within a selection field

My webgui testing involves the use of selenium, which includes the following method: protected static selectListItems(String id, String value1, String value2, String value3,String value4){ String values = "" if(StringUtils.isNotBlank(value1)) ...

The art of bringing a pseudo class to life through animation

Seeking assistance with achieving a unique effect on click event. I have set up a slanted or razor-blade style div using a parent div element and a pseudo-element :after (as shown below). My goal is to change the skew angle when the user clicks on the pare ...