Leveraging flask/jinja for incorporating dynamic content without the need for an HTML table

Although I'm not well-versed in web development, I hope this question is on the right track.

In my flask app, I'm trying to create a section that showcases albums/cards in a similar style as seen on this example.

My goal is to display multiple cards on the page, with a maximum of 3 or 4 cards per row, wrapping the content accordingly.

I've attempted to use flex-box to achieve this, with the following code snippet:

<div class="box" style="display:flex; max-width: 500px;">
  {% for row in x %}
  <div class="card mb-4 box-shadow" style="padding:5px; min-width: 200px; margin: 10px;">
    <div class="card-body">
      <h5>{{row.title}}</h5>
      <p class="card-text" style="font-size: 15px;">{{row.text}}</p>
      <div class="d-flex justify-content-between align-items-center">
        <div class="btn-group">
          <form action="filtersearch" name="filtersearch" method="POST" style="width: 80%;">
            <input id="namesearch" name="nameval" style="width: 80%;" placeholder={ {current_name}}>
          </form>
      </div>
      <small class="text-muted">9 mins</small>
    </div>
  </div>
</div>
  {% endfor %}

However, the cards end up extending infinitely in a horizontal manner beyond the margins.

I've utilized Flask for dynamic content display using HTML tables in the past, but I'm unsure if a layout like this is achievable. Can you offer any guidance?

Thank you for your assistance!

Answer №1

Utilize flex-flow: row wrap and justify-content: center for centering elements. Optionally, adjust margin:10px or use justify-content: space-around or justify-content: space-between. Another layout method is display: grid, learn more here.

A Complete Guide to Flexbox

See the code snippet below for reference:

section {
  max-width: 160px;
  height: auto;
  border: 1px solid #a2a2a2;
  text-align: center;
  margin: 10px;
}

img {
  width: 100%;
}

.parent--products {
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
}
<div class="parent--products">
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
  <section class="products">
    <div class="product-card">
      <div class="product-image">
        <img src="https://picsum.photos/5416/3611?image=1082">
      </div>
      <div class="product-info">
        <h5>Winter Jacket</h5>
        <h6>$99.99</h6>
      </div>
    </div>
  </section>
</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

Tips for identifying when a change has been made to a SCSS file or any of its partial files

Looking to incorporate sass into a Ruby script but want to compile only when necessary. The typical method for compiling involves using the following code: require "sass" Sass::Engine.new(File.read(scss), options).render By utilizing appropriate hash val ...

The view of the Google map is filled with numerous rounded tiles

Map divided into 3x3 tiles I am looking to customize the appearance of my map and remove all spaces and rounded corners to create a seamless, undivided visual. Is there a way to modify a map tile attribute to achieve this effect? Below is the code snippet ...

Where can I locate htmlWebpackPlugin.options.title in a Vue CLI 3 project or how can I configure it?

After creating my webpage using vue cli 3, I decided to add a title. Upon examining the public/index.html file, I discovered the code snippet <title><%= htmlWebpackPlugin.options.title %></title>. Can you guide me on how to change and cu ...

Tips for including an external babel JS (ES6) file in an HTML document:

To include the babel js file in an HTML file, take a look at the code snippet below: <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudfl ...

How can I add seconds to the jquery datetimepicker plugin?

Looking to implement the datetimepicker plugin from here, but I'm having trouble finding information on how to include the seconds part. Is there a way to add seconds to this plugin? It's a crucial requirement, so any suggestions for another good ...

How to Position an Input Text Beside an Icon Image Using JqueryMobile

Just starting out with jquery mobile and css! Check out my jsfiddle.net/mapsv3/kWJRw/1/, when I use an icon on the left side, the input text gets cut off and I can't see the end of it. ...

Is there a way to adjust the height of an image to be responsive in tailwind css?

<!-- this is the section with the services description and an image of an egg --> <!-- this is the first section with the description --> <div class="flex flex-1 flex-col items-center lg:items-start p-4"> &l ...

The JavaScript code created in CodePen doesn't seem to function properly when integrated into my website

During a learning program, I created a basic random quote generator. The code worked flawlessly on codepen.io. Using a simple JavaScript (jQuery) function, I displayed random quotes along with their authors, which were stored in an array. I ensured that t ...

Tips for dividing a div into percentages while maintaining a constant width for a div on the left side

I need help with creating a layout that involves 4 boxes. The first box (box1) should have a width of 50px on the left side, while the remaining 3 boxes should fill in the rest of the screen and be resizable. Can someone guide me on achieving this layout? ...

Exploring various viewport dimensions using Django and Selenium

I am currently experimenting with testing the characteristics of specific UI elements at various viewport sizes and media query breakpoints defined in CSS. Initially, I have a setup function that initializes a headless Chrome browser with what I believe is ...

Utilize Angular2's input type number without the option for decimal values

Is there a way to prevent decimals from being entered in number inputs for Angular 2? Instead of using patterns or constraints that only invalidate the field but still allow typing, what is the proper approach? Would manually checking keystrokes with the ...

Combining blend-mode and filter in CSS: A comprehensive guide

Looking to achieve a specific image style by transforming a full color photo in the following ways: Convert it to greyscale Adjust the black levels (via decreased opacity or brightness) Apply a "multiply" blend mode with a blue color overlay So far, I&a ...

Conceal HTML code from being displayed on a mobile device

After successfully displaying an element on mobile, I am now trying to hide it on the same platform. While I know this can be achieved with CSS using the display:none property, I want to explore alternative methods that do not involve creating unique CSS r ...

Can the server-side manipulate the browser's address bar?

Picture this scenario: a public display showcasing a browser viewing a web page. Can you send a GET or POST request from a mobile device to an HTTP server, causing an AJAX/pubsub/websocket JavaScript function to alter the displayed page on the screen? Per ...

Is there a way to track and detect alterations to an element using JavaScript or jQuery

Can I detect the addition of a specific CSS class to an element without having to create a new event? ...

How can elements be displayed differently depending on the return value of a function?

Basically, I am looking to display different content based on the status of a job: Show 'Something1' when the job is not processing Show 'Something2' when the job is running and has a status of '0' Show 'Something3&apos ...

What sets id and class apart from each other?

I understand that for id we need to use the '#' symbol and for class '.' symbol. However, I am unsure of the specific purposes of both class and id in styling CSS. Can someone provide clarification on when I should use id and when I sho ...

Deactivate the collapse toggle feature in the footer navigation

I've recently started using bootstrap and I'm having some trouble adding a social nav footer to my portfolio. I've experimented with removing different classes and even tried using the sticky footer feature, but it's not quite what I ne ...

"Transitioning from Bootstrap version 3.3.7 to the latest Bootstrap version 4.1.3

Everywhere I look, it says that Bootstrap 4.1 is compatible with Bootstrap 3, but when I update my project to the newer version, a lot of things stop working, such as this cookie consent feature. @{ Layout = ""; } @using Microsoft.AspNetCore.Http ...

How can you prevent a tag from firing in Google Tag Manager by identifying a particular script included in the HTML code

Seeking advice on modifying our Google Tag Manager container as I am a novice when it comes to GTM. Encountering an issue with IE8 on pages utilizing Fusion Charts resulting in a javascript error in gtm.js. Upon investigation, it appears to be related to a ...