Skip to content

Commit 20b37c9

Browse files
committed
post. masonry layout with three lines of css
1 parent 72831c2 commit 20b37c9

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

public/images/masonry_before.png

517 KB
Loading

public/images/masonry_landscape.png

518 KB
Loading

public/images/masonry_portrait.png

437 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "Masonry Layout with three lines of CSS"
3+
pubDate: 2025-06-04T22:30:00Z
4+
tags: ['css']
5+
---
6+
The masonry layout consists of a group of elements of unequal size, arranged in such a way that there are no uneven gaps. A clear example is the Metro menu in Microsoft Windows.
7+
8+
The following code example shows a set of images of different sizes.
9+
10+
```html
11+
<div>
12+
<img src="https://picsum.photos/seed/random10/320/400.jpg" />
13+
<img src="https://picsum.photos/seed/random20/300/400.jpg" />
14+
<img src="https://picsum.photos/seed/random30/400/400.jpg" />
15+
<img src="https://picsum.photos/seed/random40/400/320.jpg" />
16+
<img src="https://picsum.photos/seed/random50/400/300.jpg" />
17+
<img src="https://picsum.photos/seed/random60/400/400.jpg" />
18+
<img src="https://picsum.photos/seed/random70/320/400.jpg" />
19+
<img src="https://picsum.photos/seed/random80/300/400.jpg" />
20+
<img src="https://picsum.photos/seed/random90/400/400.jpg" />
21+
<img src="https://picsum.photos/seed/random100/320/400.jpg" />
22+
<img src="https://picsum.photos/seed/random110/400/300.jpg" />
23+
</div>
24+
```
25+
26+
This is what the images initially look like on screen:
27+
![Example before the CSS](/images/masonry_before.png)
28+
29+
The three lines of CSS to apply are the `column`, `gap` and `width` properties.
30+
31+
```css
32+
div {
33+
columns: 320px;
34+
gap: 4px;
35+
}
36+
img {
37+
width: 100%;
38+
}
39+
```
40+
41+
This is what the images look like after applying them:
42+
![Example after the CSS in landscape](/images/masonry_landscape.png)
43+
44+
The design even adapts to different screen sizes and orientations:
45+
![Example after the CSS in portrait](/images/masonry_portrait.png)
46+
47+
Thanks to the advances of CSS, a complex design that previously required multiple lines of CSS, in addition to the use of JavaScript, can now be implemented with just a few lines of CSS.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "Masonry Layout con tres líneas de CSS"
3+
pubDate: 2025-06-04T22:30:00Z
4+
tags: ['css']
5+
---
6+
El masonry layout consiste en un grupo de elementos de tamaño desigual, dispuestos de forma que no haya espacios desiguales. Un claro ejemplo es el menú Metro de Microsoft Windows.
7+
8+
El siguiente ejemplo de código muestra un conjunto de imágenes de diferentes tamaños.
9+
10+
```html
11+
<div>
12+
<img src="https://picsum.photos/seed/random10/320/400.jpg" />
13+
<img src="https://picsum.photos/seed/random20/300/400.jpg" />
14+
<img src="https://picsum.photos/seed/random30/400/400.jpg" />
15+
<img src="https://picsum.photos/seed/random40/400/320.jpg" />
16+
<img src="https://picsum.photos/seed/random50/400/300.jpg" />
17+
<img src="https://picsum.photos/seed/random60/400/400.jpg" />
18+
<img src="https://picsum.photos/seed/random70/320/400.jpg" />
19+
<img src="https://picsum.photos/seed/random80/300/400.jpg" />
20+
<img src="https://picsum.photos/seed/random90/400/400.jpg" />
21+
<img src="https://picsum.photos/seed/random100/320/400.jpg" />
22+
<img src="https://picsum.photos/seed/random110/400/300.jpg" />
23+
</div>
24+
```
25+
26+
Así es como se ven inicialmente las imágenes en la pantalla:
27+
![Ejemplo antes del CSS](/images/masonry_before.png)
28+
29+
Las tres líneas de CSS a aplicar son las propiedades `column`, `gap` y `width`.
30+
31+
```css
32+
div {
33+
columns: 320px;
34+
gap: 4px;
35+
}
36+
img {
37+
width: 100%;
38+
}
39+
```
40+
41+
Así es como se ven las imágenes después de aplicarlas:
42+
![Ejemplo tras el CSS en horizontal](/images/masonry_landscape.png)
43+
44+
El diseño incluso se adapta a diferentes tamaños y orientaciones de pantalla:
45+
![Ejemplo tras el CSS en vertical](/images/masonry_portrait.png)
46+
47+
Gracias a los avances de CSS, un diseño complejo que antes requería múltiples líneas de CSS, además del uso de JavaScript, ahora se puede implementar con solo unas pocas líneas de CSS.

0 commit comments

Comments
 (0)