My goal is to center items within a layout that uses either inline-flex or inline-block positioning

https://i.sstatic.net/F7dXv.png

My goal is to align the left and right margins equally. I have a set of nft cards that I want to display in a grid format, similar to the image provided. However, I am having trouble centering them on the page. I simply want to showcase them in a clean grid layout.

<div className="a-nfts">
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
            <div className="a-nft-card">A</div>
</div>
//css
.a-nft-card{  
  display: inline-block;
  height: 400px;
  width: 300px;
  background-color: #000309;
  border-radius: 10px;
  border: white 1px solid;
}
.a-nfts{  
  
  width: 60%; 
  border: 1px solid white;
  margin: auto; 
}

Answer №1

If you encase them in a flex container and tweak the properties to flex-wrap:wrap and justify-content: center, it will align the cards at the center. Does that meet your requirements? I've highlighted the container in blue for better visualization.

.container {
  background-color: lightblue;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.a-nft-card {
  display: inline-block;
  height: 400px;
  width: 300px;
  background-color: #000309;
  border-radius: 10px;
  border: white 1px solid;
  color:white;
}

.a-nfts {
  width: 60%;
  border: 1px solid white;
  margin: auto;
}
<div class="a-nfts">
  <div class='container'>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</div>
    <div class="a-nft-card">A</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

The application experiences crashes when the tablet is rotated, happening while in the development stage

For my web-based Android application project, I am utilizing PhoneGap and Eclipse IDE on a Windows platform. My focus is specifically on Tablet development, more precisely on the Samsung Galaxy Tab 10.1. To develop, I use Eclipse and test the app on the ...

Display or conceal several elements using JQUERY/HTML upon hovering

Here is the current progress: <div style="position: relative;"> <a href="#games"> <div class="sidenavOff"> <img src = "images/card_normal.png" /> <img src = "images/category_icons/icon_games.png" style = "position: a ...

The HTML element does not expand to fill the entire page

I recently encountered a problem with my website. Everything was functioning smoothly until I decided to add some in-page links to a large page. After adding the links, the background no longer stretched the entire length of the page. When scrolling down, ...

Stop the execution of the setTimeout function when the webpage loads in JavaScript

In my postgres database, I have a table named students for storing student information. The structure of the table is as follows: id first_name last_name time_remind 1 pers1 pers1_name 2022-07-30 21:30 2 pers2 pers2_name 2022-07-30 20:38 Current ...

The spinner persists even after the fetch api call

The issue I'm facing with my song lyrics app is that the spinner does not disappear after fetching data from the API. It seems like JavaScript is unable to detect the presence of the spinner even though it exists when the remove function is called. I ...

Exploring the power of Angular by implementing nested ng-repeat functionalities:

I am currently working on an ng-repeat feature to add items from the array (album array). Everything seems to be functioning correctly. However, I also have a colors array that should assign different background-colors to the card elements of the album arr ...

developing a dynamic map with javascript

In the image provided, my concept is for it to initially be without a green tint. However, when the user hovers over specific areas, they would turn green and become clickable links. There are multiple areas in the image, with this being just one example. ...

Issue with hiding elements in Bootstrap 4 Beta using display none

Currently experimenting with Bootstrap 4 beta through the CDN, I have encountered a peculiar issue with the newly introduced d-* class. Upon trying out a simple div with the class "d-none d-lg-block", it performed as expected, being visible only when the ...

Understanding the behavior of Window.open() function with Http:// and Https:// protocols on iOS devices

I have a form that includes multiple fields along with two icons that redirect the user to a new tab. First Link <span class="uk-input-group-addon"> <a onclick="window.open('https://www.myURL.com/folder1/page_name', '_blank&apos ...

Issue with "repeat-x" causing distortion in mobile image display

My repeating background image (.png) looks great on desktop with repeat-x, but on mobile, it has a slight repeat-y edge at the top: https://i.sstatic.net/yFfea.jpg The source image is 300px wide and 100px high, and the CSS for this div is: background: u ...

Having trouble with the margin for the first/last child in your Next.js and Tailwind CSS setup?

A similar situation arose in relation to this GitHub issue I came across. https://github.com/tailwindlabs/tailwindcss/issues/1930 In the context of Next.js and Tailwind CSS, there seems to be an issue with the First / Last child for margin not functionin ...

Is there a way to achieve horizontal alignment for the Twitter and Facebook buttons on my page?

By utilizing the html code provided, I successfully incorporated Twitter and Facebook "Like" buttons into my website. Initially, they were stacked vertically, which resulted in excessive use of vertical space. To optimize space usage, I decided to align th ...

Links have a longer transition delay compared to the content

In a unique JavaScript function I've developed, the my-content-section-visible class is removed and replaced with my-content-section-hidden. This change is being made to hide a particular div using a smooth transition effect. The transition itself is ...

What are the steps to resize a YouTube embedded video?

I am currently attempting to use a YouTube video as the background for breadcrumbs on my website. However, I am facing an issue with setting the video width to cover the full screen. The image below shows that the video is displayed in the center of the if ...

Tips for initiating a function at a designated scroll point on a webpage

Currently, I am testing out a code snippet that allows images to flip through in a canvas element. I'm curious if it's possible to delay the image flipping effect until the viewer scrolls down to a specific section of the page where the canvas i ...

Transfer a GET parameter from the URL to a .js file, then pass it from the .js file to a

Hey there, I'm currently using a JavaScript file to populate my HTML page with dynamic data. The JS file makes a call to a PHP file, which then fetches information from my SQL database and echoes it as json_encode to populate the HTML page. The issue ...

What is the best way to trigger a jQuery animation when a section becomes visible using Fullpage.js?

Within my website, I've incorporated Fullpage.js and am interested in triggering jQuery animate functions as users scroll to specific sections. Although I tested methods like mouseenter, mouseover, and mouseleave from the prior section, they did not d ...

When setting the margin to auto, it perfectly centers elements on servers and IE, but on Chrome off the server, it appears to be aligned to the

There seems to be an issue with the display of my page in Chrome - it starts at the middle and ends on the right side. However, when I view it on my server or try it on Internet Explorer 11, it appears centered. Why is that? This problem only arose after ...

Unable to input information into Textbox in real-time

Having trouble entering data from one page to another using ng-model. After filling in some information in a textbox and moving to the next page, I want the same data to be entered when I return to the previous page. I've written the code but it doesn ...

Exploring the asynchronous for loop functionality in the express.js framework

I'm attempting to use a for loop to display all images. I have stored the paths of the images in an array called Cubeimage. However, when trying to display them using <img>, I encountered an error. How can I write asynchronous code to make it wo ...