# jQuery Mobile

Navigation Home

# Grids API

The jQuery Mobile framework provides a simple way to build CSS-based columns that can also be responsive. Jump to section

## Grid basics

Grids are 100% width, completely invisible (no borders or backgrounds) and don't have padding or margins, so they shouldn't interfere with the styles of elements placed inside them.Within the grid container, child elements are assigned `ui-block-a/b/c/d/e` in a sequential manner which makes each "block" element float side-by-side, forming the grid.

## Two column grids

To build a two-column (50/50%) layout, start with a container with a `class` of `ui-grid-a`, and add two child containers inside it classed with `ui-block-a` for the first column and `ui-block-b` for the second. On the blocks below, we're adding two classes: `ui-bar` to add the default bar padding and `ui-bar-e` to apply the background gradient and font styling for the "e" toolbar theme swatch. For illustration purposes, an inline `style="height:120px"` attribute is also added to each grid to set each to a standard height.

Block A
Block B

Grid classes can be applied to any container. In this next example, we add `ui-grid-a` to a `fieldset`, and apply the `ui-block` classes to the container of each of the two buttons inside to stretch them each to 50% of the screen width:

## Three-column grids

The other grid layout configuration uses `class=ui-grid-b` on the parent, and 3 child container elements, each with its respective `ui-block-a/b/c` class, to create a three-column layout (33/33/33%).

Block A
Block B
Block C

And an example of a 3 column grid with buttons inside:

## Four-column grids

A four-column, 25/25/25/25% grid is created by specifying `class=ui-grid-c` on the parent and adding a fourth block.

A
B
C
D

## Five-column grids

A five-column, 20/20/20/20/20% grid is created by specifying `class=ui-grid-d` on the parent and adding a fifth block.

A
B
C
D
E

## Multiple row grids

Grids are designed to wrap to multiple rows of items. For example, if you specify a 3-column grid (ui-grid-b) on a container that has nine child blocks, it will wrap to 3 rows of 3 items each. There is a CSS rule to clear the floats and start a new line when the `class=ui-block-a` is seen so make sure to assign block classes in a repeating sequence (a, b, c, a, b, c, etc.) that maps to the grid type:

A
B
C
A
B
C
A
B
C

## Grid solo class

Please note that the framework adds left and right margin to buttons in a grid. For a single button you can use a container with class `ui-grid-solo` and wrap the button in a div with class `ui-block-a` like the example below. This way the button will get the same margin.

## Responsive grids

It's straightforward to take the standard grids and make them responsive by stacking the grid blocks at narrow widths. Since we just want to override the floats and widths of the standard grid styles below a single breakpoint, use a `max-width` breakpoint to only apply the stacked styling as an override.

We recommend adding a class (ex: `my-breakpoint`) to scope the styles for the media query so it can be applied selectively. From this basic start, you can customize the appearance further or even add additional breakpoints. See an example of a custom responsive grid.

    /* stack all grids below 40em (640px) */
    @media all and (max-width: 35em) {
    	.my-breakpoint .ui-block-a,
    	.my-breakpoint .ui-block-b,
    	.my-breakpoint .ui-block-c,
    	.my-breakpoint .ui-block-d,
    	.my-breakpoint .ui-block-e {
    		width: 100%;
    		float:none;
    	}
    }

## Breakpoint preset

To apply a preset breakpoint to stack grids below 35em (560px), add the `.ui-responsive` class to the grid container.

### Grid A (50/50)

Block A
Block B

### Grid B (33/33/33)

Block A
Block B
Block C

### Grid C (25/25/25/25)

A
B
C
D

### Grid D (20/20/20/20/20)

A
B
C
D
E