<div id="wrap">

	<!-- section -->
	<div class="section">
		<div class="center">

			<div id="gallery" class="contains-1">
				<div class="gal"><span>1</span></div>
			</div>
			
			<div id="add">
				<span>Добавить</span>
			</div>

		</div>
	</div>
	<!--/section -->

</div>
html,
body {
	margin: 0;
	padding: 0;
	font-family: sans-serif;
	font-size: 16px;
	line-height: 1.4;
	color: #555;
	background: #fff;
}

* {
	box-sizing: border-box;
}

#wrap {
	position: relative;
}

.section {
	padding: 40px;
}

#gallery {
	margin: auto;
	width: 900px;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
	grid-auto-flow: row dense;
	grid-auto-rows: 300px;

	&.contains {
		&-1 {
			.gal {
				grid-row-end: span 2;
			}
		}
		
		&-2 {
			.gal {
				grid-row-end: span 2;
				
				&:nth-child(2) {
					grid-column-start: span 2;
				}
			}
		}
		
		&-3 {
			.gal {
				grid-row-end: unset;
				
				&:nth-child(1) {
					grid-column-end: span 2;
				}
				
				&:nth-child(3) {
					grid-column-end: span 3;
				}
			}
		}
		
		&-4 {
			.gal {
				
				&:nth-child(1) {
					grid-row-end: span 2;
				}
				
				&:nth-child(4) {
					grid-column-start: span 2;
				}
			}
		}
		
		&-5 {
			.gal {
				
				&:nth-child(5) {
					grid-column-end: span 2;
				}
			}
		}
	}
}

.gal {
	max-height: 100%;
	overflow: hidden;
	position: relative;

	span {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		font-size: 24px;
		font-weight: 700;
	}

	&:nth-child(1) {
		background: #aaa;
	}

	&:nth-child(2) {
		background: #bbb;
	}

	&:nth-child(3) {
		background: #ccc;
	}

	&:nth-child(4) {
		background: #ddd;
	}

	&:nth-child(5) {
		background: #eee;
	}
}

#add {
	width: 100%;
	padding: 10px;
	text-align: center;
	text-transform: uppercase;
	cursor: pointer;
	background: #ccc;
	font-weight: 700;
	margin-top: 20px;
	user-select: none;

	&:hover {
		background: #bbb;
	}

	&.hide {
		display: none;
	}
}
View Compiled
$(function() {
	var $gallery = $('#gallery'),
		i = 1;
	
	function checkGal() {
		var $gals = $gallery.children().length;
		
		$gallery.attr('class', 'contains-' + i);
	}
	
	$('#add').click(function() {
		i++;
		
		if(i >= 5) {
			$('#add').addClass('hide');
		}
		
		$('.gal').last().clone().html('<span>' + i + '</span>').appendTo('#gallery');
		
		checkGal();
	});
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js