Masonry-Style Layout in CSS

Developer
Size
2,116 Kb
Views
32,384

How do I make an masonry-style layout in css?

Masonry's a pretty neat piece of work, but why use all that js?. What is a masonry-style layout in css? How do you make a masonry-style layout in css? This script and codes were developed by Matt Gross on 28 August 2022, Sunday.

Masonry-Style Layout in CSS Previews

Masonry-Style Layout in CSS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Masonry-Style Layout in CSS</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- Section with a bunch of items in it. I'm using images, but in principle this should work with whatever. -->
<section class="container"> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97450&w=350&h=450" alt="" /> </div> <p>And this is some Text, just chucked right in the middle.</p> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97350&w=350&h=350" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97250&w=350&h=250" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97250&w=350&h=250" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=750%C3%971250&w=750&h=1250" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97450&w=350&h=450" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97550&w=350&h=550" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97350&w=350&h=350" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97350&w=350&h=350" alt="" /> </div> <div class="item"> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97550&w=350&h=550" alt="" /> </div>
</section>
</body>
</html>

Masonry-Style Layout in CSS - Script Codes CSS Codes

/* Basic Reset */
* { margin: 0; padding: 0; box-sizing: border-box;
}
body { padding: 30px;
}
/* Styles for the grid */
.container {
/* Number of columns */	-webkit-column-count: 3; -moz-column-count: 3; column-count: 3;
/* horizontal space between blocks */	-webkit-column-gap: 1px; -moz-column-gap: 1px; column-gap: 1px;
}
.item {
/* Vertical space between items */ margin-bottom: 1px;
/* Keeps the individual blocks of content from breaking, good for mixed content, but not necessary. */ -webkit-column-break-inside: avoid; page-break-inside: avoid; break-inside: avoid;
}
/* Useful styling for the images, keeps them in place & preserves their aspect ratio */
.item img { display: block; width: 100%; height: auto;
}
/* Responsive too! */
@media (max-width: 740px) { .container { -webkit-column-count: 2; -moz-column-count: 2; column-count: 2; }
}
@media (max-width: 520px) { .container { -webkit-column-count: 1; -moz-column-count: 1; column-count: 1; }
}
Masonry-Style Layout in CSS - Script Codes
Masonry-Style Layout in CSS - Script Codes
Home Page Home
Developer Matt Gross
Username mattgrosswork
Uploaded August 28, 2022
Rating 3
Size 2,116 Kb
Views 32,384
Do you need developer help for Masonry-Style Layout in CSS?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Matt Gross (mattgrosswork) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!