Self Correcting Grid. No classes!

Developer
Size
2,642 Kb
Views
26,312

How do I make an self correcting grid. no classes!?

I've made a 'grid' that is impermeable to unsightly gaps using pseudo-classes, the general sibling combinator and one Sass for loop.. What is a self correcting grid. no classes!? How do you make a self correcting grid. no classes!? This script and codes were developed by Heydon on 21 August 2022, Sunday.

Self Correcting Grid. No classes! Previews

Self Correcting Grid. No classes! - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Self Correcting Grid. No classes!</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p>Below is a list displayed as a grid. Thanks to pseudo classes, the general sibling combinator and a Sass <code>for</code> loop, you can change the number of columns (the <code>$cols</code> variable) and items (<code>&lt;li&gt;</code>s) and it will 'self correct' to eliminate gaps. No classes; no worries. For more info on the underlying CSS involved, read <a href="http://www.heydonworks.com/article/tetris-the-power-of-css"><i>Tetris and The Power Of CSS</i></a>.</p>
<ul> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ul>
</body>
</html>

Self Correcting Grid. No classes! - Script Codes CSS Codes

/* choose a number of columns */
li { /* set up the basic item widths */ width: 33.33333%;
}
/* this for loop does everything else using nth-child,
nth-last-child and general siblings */
li:nth-child(3n+1):nth-last-child(1) { width: 100%;
}
li:nth-child(3n+1):nth-last-child(1) ~ li { width: 100%;
}
li:nth-child(3n+1):nth-last-child(2) { width: 50%;
}
li:nth-child(3n+1):nth-last-child(2) ~ li { width: 50%;
}
li:nth-child(3n+1):nth-last-child(3) { width: 33.33333%;
}
li:nth-child(3n+1):nth-last-child(3) ~ li { width: 33.33333%;
}
/* below is just boilerplate styles */
* { font-family: sans-serif; margin: 0; padding: 0; border: 2px solid #fff;
}
body { padding: 1em; max-width: 900px; margin: 0 auto;
}
p { margin-bottom: 1em;
}
li { float: left; font-size: 1.5em; font-weight: bold; height: 3em; line-height: 3; margin: -2px; list-style: none; text-align: center; background: #222; color: #fff;
}
code { font-family: monospace;
}
Self Correcting Grid. No classes! - Script Codes
Self Correcting Grid. No classes! - Script Codes
Home Page Home
Developer Heydon
Username heydon
Uploaded August 21, 2022
Rating 4.5
Size 2,642 Kb
Views 26,312
Do you need developer help for Self Correcting Grid. No classes!?

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!

Heydon (heydon) Script Codes
Create amazing captions 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!