The Terrible Twenties

I am stuck at a point in time where I feel like a plethora of different versions of myself are trapped inside my singular, fragile, imperfect body. There are versions of myself that I aspire to be…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to create an image gallery with CSS Grid

Now, let’s create an 8x8 grid. We can create a grid of other sizes also but that depends on the type of gallery you want. In our case, an 8x8 grid will be ideal.

HTML:

CSS:

8x8 CSS Grid (8 Column Tracks & 8 Row Tracks) with Grid Lines from 1 to 9 (Both Columns & Rows)

Now, we will be inserting the grid items inside the grid container:

Setting the object fit value to cover is like setting the background size to cover for the background image. We are doing this so the image can fill the height and width of its box (the grid item), maintaining its aspect ratio.

Before we start positioning the grid items, we will study a few basics concepts.

The grid div is the grid container, and all the direct child elements are the grid items. When we defined the grid tracks with grid-template-columns and grid-template-rows, grid provided us numbered lines called the grid lines to use for positioning the items. You can refer to each grid line by a numerical index.

Columns start at one, from left to right by default, and rows also begin at one from top to bottom. It takes two grid lines to make a single column or row, one line on either side, so our 8-column and 8-row grid consist of
9-column lines and 9-row lines.

The vertical lines 1 and 2 determine the start and end points of the first column. Lines 2 and 3 the second column and so on. Similarly, horizontal lines 1 and 2 determine the position of the first row, and lines 2 and 3 the second row and so on. Knowing the above concepts will help you understand how we are going to position items (images) on our grid.

Now, we will use grid line numbers to control how items are placed by applying properties directly to a grid item. We can specify on which line a grid item starts and ends, and how many tracks it should expand.

So let’s create a new rule that targets the first grid item. We’ll first use the grid-column-start property to indicate the column grid line where the first grid item starts. The grid-column-end indicates where the first grid item ends.

So the grid-column-start value is a number that indicates the grid line at the left edge of a column. The grid-column-end value indicates the grid line that marks the right edge of the column.

So in the example given below, setting grid-column-start to 1 and grid-column-end to 3 means that the grid item will stretch from the left edge of the grid line, line 1 to line 3, filling up 2 columns. We will also use the grid-row-start and grid-row-end properties to indicate the grid item start and end position on the row grid lines in the same way as we did for the column.

First Item Placement
Second Item Placement
Fourth Item Placement
Sixth Item Placement

You can find the complete code in Github Gist given below.

You can try adding your own CSS to make this gallery look the way you want it to look. You can also create more complex image galleries very easily.

You can learn more about the CSS Grids in the link given below

I hope you’ve found this post informative and helpful. I would love to hear your feedback!

Thank you for reading!

Add a comment

Related posts:

NBK43

Considering how little I have done the ‘dating thing’ in my life, I never thought I would start to experience virtual social fatigue. I should distinguish. I actually like being around people…

Setup Hadoop psuedo cluster on Ubuntu 16.04

This article to set up Hadoop on your personal Ubuntu machine from scratch. Please follow step by step and you will be able to start the Hadoop process along with yarn and we will also demonstrate…

Grand fortune casino no deposit bonus codes

Join Grand Fortune Casino & Get $/€50 Free No Deposit Bonus. Last Modified 17 June 2020. Get Bonus. Users Claimed 1463. Max Bonus: $/€50 Free Bonus. Wagering Requirement: 35x. Min Deposit. Redeen…