Home > Web Front-end > CSS Tutorial > How to Achieve 1px Spacing Between Flex Items in an Image Gallery?

How to Achieve 1px Spacing Between Flex Items in an Image Gallery?

Susan Sarandon
Release: 2024-12-24 18:44:54
Original
774 people have browsed it

How to Achieve 1px Spacing Between Flex Items in an Image Gallery?

How to Adjust Spacing in Image Gallery Flex Items with Margins

In flexbox layouts, items with flex values of '0 0 25%' have a fixed width and do not shrink or grow. To add space between these items while maintaining a grid-like structure, margins can be applied. However, applying a 1% margin results in gaps that may be too large.

To achieve a 1px margin, use the flex value '1 0 22%'. This sets the flex-basis to 22%, ensuring that there are only four items per row. The flex-grow value is set to 1, allowing the items to grow and fill the remaining space left by the margins. This creates a subtle 1px gap between the items.

#foto-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  margin: 10px;
}

.foto {
  flex: 1 0 22%;
  min-height: 50px;
  margin: 1px;
  background-color: red;
}
Copy after login

The above is the detailed content of How to Achieve 1px Spacing Between Flex Items in an Image Gallery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template