Achieve dynamic centering for a list of cards without using CSS to center each card individually

How can I center the .thumbs_container within .thumbswrapper while displaying 5 cards (.thumbs), ensuring that they remain aligned even if only 3 are displayed on the first line?

.thumbs_wrapper {
    width: 50%;
    background-color: #F6F6F6;
    padding: 56px 50px;
    border-radius: 25px;
}


.thumbs_container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px 25px;
    margin: 0 auto;
}

.thumb {
    position: relative;
    background-color: red;
    height: 100px;
    width: 100px;
    border-radius: 10px;
    overflow: hidden;
}
<div class="thumbs_wrapper">
  <div class="thumbs_container">
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></div>
  </div>
</div>

Answer №1

This snippet of code is designed to center the thumbs_container within the thumbs_wrapper using Flexbox properties.

.thumbs_wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #F6F6F6;
    padding: 56px 50px;
    border-radius: 25px;
}


.thumbs_container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px 25px;
    margin: 0 auto;
}

.thumb {
    position: relative;
    background-color: red;
    height: 100px;
    width: 100px;
    border-radius: 10px;
    overflow: hidden;
}
<div class="thumbs_wrapper">
  <div class="thumbs_container">
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></div>
    <div class="thumb"></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

I'm having trouble receiving HTML content through Ajax or inserting the response into a DIV using JQuery

I'm having trouble retrieving a simple response from a controller and displaying it in a div so that I can view the output on the front end. Below is my JQuery code: $('.js-mapsearch').keyup(function (e) { var characters = $(t ...

How can Vuetify be used to create a v-row that floats above other elements, maintains a fixed position, and still adheres to the width of its parent element

Currently, I am integrating Vuetify into my project and facing an issue with making an element inside a v-row float and fixed while still maintaining the width of the parent element. Here's the code snippet I am working with: <v-container> ...

Guide on navigating through various HTML pages with distinct parameters using Node.js (Express server)

Seeking assistance with a Node.js server that receives an ID as a query parameter. Each time a client connects with different parameters, I aim to serve them a unique HTML page containing a simple UI with 2 dynamic arrays. Everything seems to be working co ...

JavaScript/CSS memory matching game

Just starting out in the world of programming and attempting to create a memory game. I've designed 5 unique flags using CSS that I want to use in my game, but I'm feeling a bit stuck with where to go next. I understand that I need some function ...

The impressive wipe effect in velocity.js using css and jquery

I am looking to achieve a slide effect similar to Powerpoint's wipe using css, jquery, or velocity.js. Here is a video showing the desired effect: https://www.youtube.com/watch?v=VSBB0wfccws I attempted to use css3 masking (svg/gradient) but was uns ...

Automatic table width expansion with CSS

I'm in the process of creating a new website, and I want the layout to resemble the following: +---+--------------+ |# | | |n | #page | |a | table.basic | |i | | |g | | |a | | |t | ...

Increasing and decreasing the display of content using JQuery based on height rather than character count

I'm attempting to create a show more/show less link with a set height of 200px that, when clicked, will reveal the rest of the content. Anything exceeding 200px will be hidden, and there will be a "show more" link to display the remaining text. I&apos ...

Get rid of the underlined anchors in your email signature

I'm currently in the process of creating personalized email signatures for one of my clients. At this point, I am testing them on various platforms such as GMail, Hotmail, Brinkster, and more. One issue I am facing is trying to remove the underline t ...

What is the best way to prevent the page location from changing while downloading a PHP file generated through a post request?

Having a file called download.php, I send data via a POST request to generate an SVG file for downloading by setting the header with: header('Content-Type: application/svg+xml'); header("Content-Disposition: attachment; filename=\"myfilenam ...

Any tips on getting rid of the spacing between my Bootstrap 4 links?

I am facing an issue with implementing Bootstrap 4 inline-block links. There seems to be an invisible margin between them that I cannot remove. Screenshot: View the Codepen example here. Code: <div> <!-- There shoud be NO MARGIN between th ...

Today's date-based counter

Can someone help me create an HTML code for a list of the next 10 weekdays from today? I specifically need the dates to be in French. Here is the function I am currently using to translate the date: function f_date() { $temps = time(); $jours = ar ...

Ways to populate dynamic choices for multiple Select boxes within an ng-repeat loop

When I click the "Add Row" button on an Html form, dynamic rows are added. Each row contains a 'Country' select and a 'State' select. The issue I am facing is that when I select a country in one row, all other row values change as well. ...

Using @Input to pass data from a parent component to a

Looking to modularize the form code into a separate component for reusability? Consider using @Input and referencing it in the HTML to pass values to the post method. Here's how you can achieve this: Previously, everything worked smoothly when all th ...

Utilizing URL Hashes to Integrate Isotope Filtering: A Comprehensive Guide

(Even though Wordpress is mentioned, I believe this problem is not specific to Wordpress) I am currently building my own website using Wordpress and the theme I'm using includes the Isotope by Metafizzy package. This package helps in filtering posts ...

Update the background color of an li element upon clicking

Is there a way to change the background color upon clicking on the li anchors? <div class="text-center row"> <ul class="col-md-12 secondNav"> <li class="navbar-brand nav-item" style="margin-right: 9%"> <a href="#" >& ...

Using PHP to filter data using $_GET variables?

https://i.sstatic.net/vDqe3.png In order to sort the small divs based on specific filters like AB Main Hall, AB Club, Huis 23, I believe using $_GET is necessary. Here is the code snippet I currently have. <?php $concert = [ [ "datum" =& ...

Unable to incorporate CSS background image

https://i.sstatic.net/3ZLq3.jpg[ I've been working on designing the main page using Bootstrap, but I'm facing an issue with adding a background image. I've tried multiple methods such as adding it to the CSS body and directly in the HTML co ...

How can I achieve a letter-spacing of 0.5 pixels in CSS?

Encountering an issue, I set out to enhance readability by adjusting letter-spacing to 1px. Displeased with the result, I attempted a half pixel spacing of 0.5px but found it ineffective. Subsequently, I experimented with em attributes but failed to accomp ...

Dynamic Display Picture Banner - Adjustable Layout

My home page features a full screen image header that I'm working to make responsive. The width of the image is being cut off on various screen sizes. I've attempted adjusting the height and width settings, but I want the image itself to resize ...

implementing a smooth transition effect for image changes upon hover

I've been working on a React project where I created a card that changes its image when hovered over. I wanted to add a smoother transition effect to the image change using transition: opacity 0.25s ease-in-out;, but it doesn't seem to be working ...