This code creates a skewed grid image gallery using CSS. It arranges images in rows and columns. The gallery allows for hovering effects, enlarging selected images for better viewing. The layout adjusts responsively based on screen size, optimizing for different devices.
You can use this code on websites displaying image collections, like portfolios or galleries. It offers an engaging layout that showcases images dynamically. Plus, it adjusts seamlessly for various screen sizes, ensuring a great user experience.
How to Create Skewed Grid Image Gallery In Css
1. Start by setting up the HTML structure. Use an <article>
tag with a class name “gallery”. Inside this tag, include <img>
tags with their respective image sources and alt attributes for accessibility. Optionally, use <div>
elements with a class “spacer” to add space between images.
<article class="gallery"> <img src="https://assets.codepen.io/1506195/unsplash-music-0.avif" alt="guitar player at concert" /> <blockquote class="quote spacer"> <span>Without music, life would be a mistake.</span> <cite>—Friedrich Nietzsche</cite> </blockquote> <img src="path/to/your-image.jpg" alt="duo singing" /> <img src="path/to/your-image.jpg" alt="crowd cheering" /> <img src="path/to/your-image.jpg" alt="singer performing" /> <img src="path/to/your-image.jpg" alt="singer fistbumping crowd" /> <div class="spacer"></div> <img src="path/to/your-image.jpg" alt="crowd cheering" /> <img src="path/to/your-image.jpg" alt="crowd in a concert" /> <img src="path/to/your-image.jpg" alt="woman singing" /> <div class="spacer"></div> <div class="spacer"></div> <img src="path/to/your-image.jpg" alt="Person playing a cello" /> <img src="path/to/your-image.jpg" alt="Kiss playing" /> <img src="path/to/your-image.jpg" alt="young man singing" /> <div class="spacer"></div> <img src="path/to/your-image.jpg" alt="woman singing" /> <img src="path/to/your-image.jpg" alt="man playing drums" /> </article>
2. After that, apply the following CSS styles to the image grid. It handles the layout, positioning, and hover effects for the gallery. It utilizes CSS Grid to arrange images in a skewed grid pattern and transitions for hover effects. Customize font styles, colors, and breakpoints for responsiveness if needed.
@font-face { font-family: 'Montserrat'; font-style: normal; font-weight: 400; font-display: swap; src: url(https://fonts.gstatic.com/s/montserrat/v26/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-.ttf) format('truetype'); } body { margin: 0; min-height: 100vh; display: grid; place-items: center; } .gallery { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 100px; gap: 0px 20px; width: clamp(70vmin, 900px, 90%); } .gallery:has(img:hover) img:not(:hover) { filter: brightness(0.35); } .gallery img { object-fit: cover; width: 100%; height: 100%; clip-path: polygon(0 20px, 100% 0, 100% calc(100% - 20px), 0 100%); transition: clip-path 0.5s, transform 0.5s, filter 0.75s; transform: scale(1); } .gallery img:nth-child(3n):not(:nth-last-child(-n+4)) { grid-row: span 2; } .gallery img:nth-child(14n):not(:nth-last-child(-n+4)) { grid-row: span 2; } .gallery img:hover { transform: scale(1.3); z-index: 1; width: 100%; aheight: auto; aaspect-ratio: 1; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); transition: clip-path 0.5s, transform 0.5s, filter 0.5s; } .gallery .spacer { background: #c00; clip-path: polygon(0 20px, 100% 0, 100% calc(100% - 20px), 0 100%); box-sizing: border-box; } .gallery .quote { grid-row: span 3; margin: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px; color: #eee; font-family: Montserrat; font-size: 0.9em; } .gallery .quote span { text-wrap: balance; margin: 0 auto 15px auto; max-width: 80%; line-height: 1.5; } .gallery .quote span::before { content: "\""; font-size: 4em; font-family: Georgia, 'Palatino Linotype', 'Times New Roman', serif; vertical-align: middle; line-height: 0; color: #fff8; } @media all and (max-width: 700px) { .gallery { grid-template-columns: repeat(3, 1fr); } } @media all and (max-width: 500px) { .gallery { grid-template-columns: repeat(2, 1fr); } } @media all and (max-width: 400px) { .gallery { grid-template-columns: repeat(1, 1fr); } }
Adjust the gallery by adding or removing images as needed. Ensure that each image has an appropriate alt attribute for accessibility. Test the gallery on different devices and screen sizes to ensure it adapts responsively.
That’s all! hopefully, you have successfully created the Skewed Grid Image Gallery In CSS. If you have any questions or suggestions, feel free to comment below.
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.