npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

basscss-grid-layout

v1.0.0

Published

Grid Layout Using CSS Grid

Downloads

8

Readme

BassCSS Grid Layout

BassCSS provides a great base from which to build a set of utility-first styles. Unfortunately, it was built before CSS Grid became widely supported and so ships with a grid system that is float-based. While that works, CSS Grid is more powerful and flexible, all without requiring negative margins to compensate for the gutters.

This module is built to complement BassCSS by mimicking its naming conventions and using the same CSS variables. As a result, it should slot smoothly in place next to BassCSS. As it is also fully self-contained, it can be used independently of BassCSS.

The styles contained within are composable, immutable utilities that are designed to each do one thing, do it well, and to be extended by user-defined styles in each project's stylesheets. As such, do not feel limited to the styles that are provided.

Defining a Grid

To start out with, define your grid container by adding the grid class to it. The immediate children of this element will be arranged into a grid. Unfortunately, your grid won't be very grid-like until you define some columns.

Setting Columns

CSS Grid provides several powerful ways to define a grid to be exactly what your project needs. The possibilities are too varied to be encoded into a utility module like this, but the basic notion of a regular columnar grid translates well into utility styles and should cover most needs.

To set the number of columns within a grid container, add one of the grid-col-X classes to your grid container, where X is the desired number of columns. There are classes for 2, 3, 4, 6, 8, 9, 12, and 16 column layouts.

Of course, you're always free to define your own classes to set columns as well.

Responsive Columns

Column sizes are also responsive with the sm-, md-, and lg- prefixes, which come into effect at the same break points as for BassCSS. This includes an additional prefix of xl- for extra large screens at two size increments (12em) above lg-.

Spanning Columns

It's common to need some grid items to span multiple columns. For this, add one of the grid-col-span-X classes to the element that needs to span multiple columns. As with the column definitions, these classes are responsive with the same set of prefixes.

Getting into the Gutter

Without further classes, your grid will contain no space between grid items. We'll want to let the items have some space, so there are utilities to add some space between your rows and your columns. col-gap-X will set spaces between columns, while row-gap-X will set spaces between rows. gap-X will set both at once. X follows the same sizes as BassCSS spaces, so gap-2 will add as much space between grid items as mb2 would add beneath an element.

Grid Item Alignment

By default, grid items are stretched to fill their respective slots in the grid. There are several classes available to fine-tune this. Some can be set on the grid container to affect all items, while others go onto individual grid items for more targeted adjustments.

On the Grid Container

For vertical alignment, use align-items-center, align-items-end, and align-items-start to align items to the center, bottom, or top of their grid areas. align-items-stretch is also available to return to the default of stretching them.

Horizontal alignment uses the justify-items-center, justify-items-end, justify-items-start, and justify-items-stretch classes.

Both vertical and horizontal can be set at the same time by items-center, items-end, items-start, and items-stretch.

On Individual Grid Items

The classes for individual adjustments mirror those that go directly on the grid container.

align-self-center, align-self-end, align-self-start, and align-self-stretch set the vertical alignment of individual items.

justify-self-center, justify-self-end, justify-self-start, and justify-self-stretch set the horizontal alignment of individual items.

self-center, self-end, self-start, and self-stretch will set both at once.

Automatic Placement of New Grid Items

Grid items that don't have specific places on a grid defined will be automatically placed horizontally after the last grid item. This behavior can be changed by setting one of the grid-auto-flow-X classes onto the grid container.

grid-auto-flow-column will cause new items to be placed vertically until the grid runs out of rows before moving on to the next column. grid-auto-flow-column-dense does the same, but will go back and fill in holes in the grid layout as it is able.

grid-auto-flow-row explicitly sets what is otherwise the default behavior of filling in a row before moving to the next while, while grid-auto-flow-row-dense will attempt to fill in earlier holes in the grid.