Yogesh Chauhan's Blog

Create a galley with overlapping images using CSS grid

in CSS on July 27, 2021

Step 1: HTML

Let’s fetch images with picsum API and add HTML with stacked on each other by default.

Step 2: Create the grid

I am using this specific code for creating rows and columns. Play with those numbers if you like.


.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: 1fr 4rem 1fr 5rem 1fr 10rem;
  margin: 0 auto;
  max-width: 800px;
}

Step 3: Place the images in the grid

Let’s adjust the images position finally and place them in the grid with overlapping on each other.

Apart from adding the grid code from above, I have set box-sizing as border-box. Adding a box-show property will add a nice tough to images. Also, images have aspect-ratio set instead of a fixed height.

This is very basic example to display the gallery with overlapping images. Experiment with it and make as complex as possible.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Why do we need HAVING Clause in SQL?SQL/MySQLSocial Media Colors: LESS VariablesMiscellaneousGeneral concepts in DrupalDrupalHow to remove WordPress TinyMCE Editor buttons?WordPressHow to install Gulp with WordPress?WordPressHow to define variables in SCSS (Sass)?SCSSWordPress plugin development: How to fix a SQL injection?WordPressWHERE Clause in PostgresPostgresPostgreSQL transactions using the BEGIN, COMMIT, and ROLLBACK statements.PostgresOptional arguments, Default parameters and REST parameters in JavaScriptJavaScriptHow destructuring works in React?ReactHow to add CurrencyPipe in TypeScript file in Angular 9 Project?Angular