Home > Web Front-end > CSS Tutorial > How Can I Add a 1px Margin to Flexbox Items with `flex: 0 0 25%`?

How Can I Add a 1px Margin to Flexbox Items with `flex: 0 0 25%`?

Linda Hamilton
Release: 2024-12-30 20:53:17
Original
1012 people have browsed it

How Can I Add a 1px Margin to Flexbox Items with `flex: 0 0 25%`?

Is There a Way to Add 1px Margin to Flexbox Elements Designated flex: 0 0 25%?

To add a 1px margin to flexbox elements set to flex: 0 0 25%, adjust the flex property to flex: 1 0 22%. This will set the element's flex-basis to 22% (allowing for four elements per row) while allowing them to grow and fill the remaining space via the 1px margin (flex-grow set to 1).

Here's an example:

#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
<div>
Copy after login

This alteration enables a 1px margin between the flex items while preserving the desired layout.

The above is the detailed content of How Can I Add a 1px Margin to Flexbox Items with `flex: 0 0 25%`?. 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