What is the best way to adjust the spacing between posts on a website

https://i.stack.imgur.com/VderY.jpg

Looking at the image, there are 3 posts lined up in a row. I'm trying to adjust the spacing between each item to be about 20%. Specifically, I want the distance highlighted by the red dashes, instead of the current distance marked by the blue arrows.
I've been exploring within the .container and .post classes but haven't quite nailed it down yet.

This is the code snippet:

.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.post {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 40px;
  width: calc(33.33% - 20px); /* 3 posts per row */
  background-color: #fff;
  transition: background-color 0.3s, transform 0.3s ease;
  display: flex;
  flex-direction: column;
  height: auto;
}

.post:hover {
  transform: translateY(-5px);
  background-color: #f8f8f8;
}

.post:active {
  transform: translateY(0);
  background-color: #fff;
}

.anime-image {
  width: 100%;
  height: auto;
  flex-shrink: 0; /* Prevent image from shrinking */
}

.anime-details {
  padding: 20px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.title {
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 10px;
}

.rating {
  font-weight: bold;
  font-size: 14px;
}
<div class="container">
@foreach (var anime in Model.Animes)
{
  <div class="post">
    <a href="url">
      <div class="anime-image-container">
        <img class="anime-image" src="@anime.Image">
      </div>
    </a>
    <div class="anime-details">
      <p class="title">@anime.Title</p>
      <p class="rating">Рейтинг</p>
    </div>
  </div>
}
</div>

Answer №1

Have you heard of the masonry layout? Look it up on Google for more information.
Check out this example to see how it works:

CSS code:

html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

.masonry {
  column-count: 3;
  column-gap: 1em;
  margin: 1.5em auto;
  max-width: 768px;
}

.item {
  display: inline-block;
  background-color: skyblue;
  width:100px;
  height: auto;
  padding: 1em;
  margin: 0 0 1em;
}

HTML code:

<div class="masonry">
  <div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="item">Some text here to fill in the gap</div>
  <div class="item">This text however is pretty longgg....... More random text to make height bigger. This is example.</div>
  <div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="item">Some text here to fill in the gap</div>
  <div class="item">Thger. This is example.</div>
  <div class="item">Lorem ipsum dolor sit amet, consectetur adipisicintetur adipisicing eg elit.</div>
  <div class="item">Some text here to fill in the gap</div>
  <div class="item">This text however is pret...... More random text to make height bigger. This is example.</div>
  <div class="item">Lorem ipsum dolor sit amet, conseclit.</div>
  <div class="item">Some text here to fill in the gap</div>
  <div class="item">This texexample.</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

Removing CSS from an HTML document using Gulp

My Web App is built using Angular and I encountered an issue with Gulp. Every time I add a new custom CSS line to my HTML file and run Gulp, it automatically removes that line from the file. <!--MATERILIZE CORE CSS--> <link h ...

Switch the CSS class for the currently selected link

There are 5 links on the page. When I click on each link, it changes color. However, when I move my cursor to another area of the page, the active link loses focus and I can't show its current state. Can you please advise me on how to fix this issue? ...

Unequal height among each div's elements

I'm struggling with creating a footer divided into 3 blocks, but they do not have equal heights, causing the border-right line to appear uneven. Here is a screenshot of the issue: Not equal height of elements Any suggestions on how to fix this? Is m ...

Can I use javascript/jquery to alter the direction of text in each line?

Looking for assistance with changing text direction on each new line. For instance: text left-to-right text right-to-left text left-to-right text right-to-left... etc. I would like the text direction to change with each word-wrap: break-word. Any help w ...

Changing color when mouse hovers using Jquery

Currently, I am in the process of converting a flash ad into an html5 ad. I found this demo here, and I would like to replicate the mouse hover effect showcased. When the cursor hovers over the details text in the banner, the entire background changes to ...

Fixing W3 Validation Errors in your Genesis theme through CSS requires a few simple steps. Let's

As a newcomer to this forum, I kindly ask for understanding regarding my current issue. Upon checking my website vocaloid.de/Wordpress/ using the W3C CSS validator, I discovered several parsing and value errors. In an attempt to solve this, I disabled all ...

Adjusting the size of content with CSS

I've been attempting to get an image to cover the entire screen on a device using CSS, but so far I haven't had any success. The image is within an :after pseudo element and content tag. Since it needs to be laid over the HTML, I can't use t ...

What steps can be taken to prevent a wrapper's CSS from affecting its enclosed elements?

My container div includes some opacity and auto height that I don't want to affect all elements within it. Is there a way to preserve the container's styles without impacting its contents? ...

Having trouble displaying one DIV above another DIV

I'm having trouble getting an image in a DIV to display above text in another DIV. I can't figure out why it's only displaying below. <div> <div style='z-index: 99; width: 160px; height: 120px; box-shadow: 0px 0px 16px 0px r ...

What is the best way to center a Checkbox in HTML5 and CSS?

I've been struggling to center my Checkbox with label on my current website project. Despite searching online for solutions, I'm still unable to find the right method! If you're curious, you can check out the source code of my webpage at ( ...

Modify the text or background shade of the Bootstrap date picker

I have successfully integrated the bootstrap date picker (view figure below) and it is functioning as expected. The code appears like this: <div class="input-group date"> <input name="departure" type="text" class="form-control" id="departure" ...

jQuery Super-sized Not Expanding Vertically

I am facing an issue with resizing a 1920x1200 background image using jQuery Supersized. Whenever I resize the browser, there is a gap that appears vertically instead of filling up to compensate for the width constraint. I have checked and copied the sett ...

Using JQuery for sliding left without having to use inline CSS

I am dealing with a situation on my website where I need to hide a sidebar when clicked. $('#sidebar').toggle('slide', 'left', 300) In addition, I have implemented a CSS style to hide the sidebar on mobile devices. #sidebar ...

Personalized hover effect using CSS on Caldera Forms

Struggling to customize the CSS style of my Caldera forms on a WordPress site. My goal is to add a hover effect to the radio checklist fields. Currently, I've only managed to style the bullets and need help adding a hover effect to the fields themselv ...

Looking for the optimal width ranges for media queries on laptops and cell phones?

Can anyone suggest the optimal width parameters to use in my code for different screen sizes, from tablets and laptops to cellphones, in order to create a responsive design? ...

Select multiple options by checking checkboxes in each row using React

Is it possible to display multiple select checkboxes with more than one per row? For example, I have four options [a, b, c, d]. How can I arrange it to have 2 options per row, totaling 2 rows instead of having 1 option per row for 4 rows? ☑a ☑b ☑c ...

Two interdependent select fields

I am currently working on creating two select fields where, upon selecting an option in the first field, some options in the second field should be hidden. I have almost achieved this, but my script is unable to locate certain options in the first select f ...

Applying CSS onmousemove does not function properly in conjunction with Bootstrap framework

Currently, I have a code snippet that enables an absolutely positioned box to follow the movement of the mouse cursor: $(document).mousemove( function(e) { $(".wordbox").css({ top: "calc(" + e.pageY + "px - 0.8em)", left: e.pageX }) ...

Utilizing Google Chrome Developer Tools for JQuery console debugging

Just started using jQuery and was expecting to see [<li>my name</li>, in the Google Chrome console but got: [li, prevObject: r.fn.init(1)] 0 : li length : 1 prevObject : r.fn.init(1) proto : Object(0) <html> ...

Adjust image size based on window dimensions changes

Let me demonstrate the issue I'm facing with this demo. This demo shows a simple list of images that scrolls across the page. When you click on an image, a larger version appears above it in a lightbox style. I want the height of this larger image ...