Implementing a horizontal card layout using a for loop in a Flask application

Currently, I have implemented a for loop to showcase a list of cars in a card layout. However, upon integrating the jinja template, the cards now appear vertically instead of horizontally.

Below is the HTML code snippet:

{% for car in cars %}
        <div class="row">
            <div class="column">
                <div class="card">

                    <ul>
                        <li>Car Name: {{ car.ev_name }}</li>
                        <li>Manufacturer: {{ car.ev_manufacturer }}</li>
                        <li>Year:{{ car.ev_year }}</li>
                        <li>Battery Size: {{ car['ev_battery_size'] }} (Kwh)</li>
                        <li>WLTP range: {{ car['ev_range'] }} (Km)</li>
                        <li>Cost: €{{ car['ev_cost'] }}</li>
                        <li>Power: {{ car['ev_power'] }} (Kw)</li>
                    </ul>
                        <br>
                    <form action="/car_details/{{ car.key.name }}" method="post" class="filter_form">
                        <input type="submit" name="show_details" class="button-1" value="Details"/>
                    </form>

                </div>
            </div>
        </div>
        {% endfor %}

Check out the CSS styling provided below:

* {
  box-sizing: border-box;
}

/* Float four columns side by side */
.column {
  float: left;
  width: 100%;
  padding: 0 10px;
}

/* Remove extra left and right margins, due to padding */
.row {
margin: 0 -5px;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive columns */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
    display: block;
    margin-bottom: 20px;
  }
}

/* Style the counter cards */
.card {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  padding: 16px;
  text-align: center;
  background-color: #f1f1f1;
  width: 800px;
  height: auto;
  margin:auto;
  font-weight: 600;
}

li {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  display: inline-block;
  width: 32%;
}

I am seeking assistance to alter the card display setting so that they are positioned adjacent to each other with an automatic adjustment of width. Any suggestions or solutions would be greatly appreciated!

Answer №1

Consider utilizing flexbox or CSS grid over using floats.

My approach would be as follows:

.row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(800px, 1fr));
    gap : 1rem
} 
 

Once you style the cards, your layout will be complete.

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

Text Alignment in a Responsive Design

Is there a way to create a responsive container that automatically centers all items inside it on the page, regardless of the screen size? Thanks :) Images are not included in this code snippet, but here's the code: HTML <!DOCTYPE html> <h ...

Learn how to apply formatting to all textboxes on an ASP.NET website using CSS without having to set the CSS class property for each individual textbox

I am currently developing a website using Asp.Net. I am looking for a way to customize the font, color, and background color of all the textboxes on my site using CSS. However, I would like to avoid having to assign a "cssclass" property to each individua ...

Create responsive sizing utility with Bootstrap 5

After exploring the Bootstrap documentation, I gained a better understanding of how to utilize the sizing utility. For instance: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8 ...

Adjust the width of the dropdown menu to match the text input field using jQuery

Struggling with jquery-mobile to collect user information, I am facing an issue aligning the width of my select menu with the text input fields. Despite successfully matching the background and border colors of the select menu with the text input fields, ...

Steps for disabling automatic formatting in Visual Studio Code Version 1.35.1 with system setup

I am currently utilizing visual studio code for my Node JS application with mustache templating. In one of my HTML files, I have the following code: <script> {{{interface}}} </script> After the automatic formatting on save, it appears like t ...

`What purpose does the data-view attribute serve in Durandal JS?`

While experimenting with the Durandal JS starter kit application, I happened to view the page source in Mozilla browser and noticed the following. <div class="" data-view="views/shell" style="" data-active-view="true"> </div> I couldn't ...

The pointer cursor seems to be missing in action

Currently using ReactJS, I have implemented a custom upload image button on my webpage. .upload-btn-wrapper { position: relative; overflow: hidden; display: inline-block; cursor: pointer; } .upload-btn-wrapper input[type=file] { font-size: 10 ...

How can you trigger a modal to appear when an image is clicked?

There are images inside <div> tags. When one of the images is clicked, a modal appears to display information about the specific image. Each modal has a unique id or class, such as modal4. My example: <image type="image" src="Images/Drake.jpg" ...

Show an SVG overlay when hovering over an image

Is there a way to create a hexagon shape around an image when it is hovered over using CSS only, even if the image itself has a circular border-radius of 50%? ...

How can I change the ActionLink in a MVC3 Grid column to an <a> tag?

Is there a way to swap out the MVC3 Grid column ActionLink with an <a> tag instead? grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { @class = "delete-button" } ), style: "column-action") ...

Retrieve the data file using input text with jQuery

Is there a way to extract data like this? data:application/pdf;base64,JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9UeXBlIC9DYXR…AKdHJhaWxlcgo8PC9TaXplIDE4Ci9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjg4MzEzCiUlRU9G from an input file? $('#file').change(functio ...

Is it possible to transform PDF files into HTML on an iOS device?

Task : Transforming a pdf file into an HTML file For example: We have a pdf file available at the link below that needs to be converted to an HTML file. Research : I searched online and discovered several methods to convert HTML to PDF such as Convert ...

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

Unable to adjust the width of a label element using CSS specifically in Safari browsers

Here's the issue I'm facing with my HTML code <input type="checkbox" asset="AAA" name="assets[AAA]" value="AAA" id="assets[AAA]" class="c_green" checked="checked"> <label for="assets[AAA]"></label> In my CSS, I have the follow ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

Ways to display an icon upon hovering or clicking, then conceal it when the mouse is moved away or another list item is clicked using ngFor in Angular 7

Within a simple loop, I have created a list with multiple rows. When a row is clicked or hovered over, it becomes active. Subsequently, clicking on another row will deactivate the previous one and activate the new one. So far, everything is functioning c ...

Show the button only when the text is updated

Is there a way to display a button only when the quantity of items in the cart changes, similar to the eBay shopping cart feature? I was able to implement it but it's not functioning as expected. Here is the link to what I have so far. Does anyone kno ...

Unexpected outcomes occur from CSS nesting

Today I realized there is still so much to learn about CSS. How is it possible that the CSS style below produces that outcome? Stylesheet: li.item a:first-child {color: red} HTML List: <ul class="mylist"> <li class="item"><a ...

Tips for inserting PHP information into the <link rel="stylesheet" type="text/css" href="CSS/sheet.css" /> reference tag

In my script, I have successfully implemented a feature that displays the OS and browser details. The output is in the form of eight CSS scripts, showcasing Mac, PC, and Ubuntu OS's with IE, Firefox, Safari, and Chrome browsers. While the script is st ...

What's the reason for the align-self: flex-end CSS property not working as expected on a flex div element?

I am trying to align the "Click me" button to the left of the div that contains it. Here is my code: render = () => { return ( <Wrapper> <Body> <span>Title</span> <Desc ...