Grids - jQuery Mobile Demos

##

Demos

Menu Search

# Grids

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

## 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-a` to apply the background and font styling for the "a" toolbar theme swatch. For illustration purposes, an inline `style="height:60px"` 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:

View more examples of buttons in grids.

## 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.

Block A
Block B
Block C
Block 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.

Block A
Block B
Block C
Block D
Block 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:

Block A
Block B
Block C
Block A
Block B
Block C
Block A
Block B
Block C

## Grid solo class

The framework adds left and right margin to buttons in a grid (one exception: 100% width button elements). 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. View more examples of buttons in grids.

Previous
Next

## 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

- Home
- Introduction
- Buttons
- Button widget

- ### Checkboxradio widget click to expand contents

  - Checkboxes
  - Radio buttons

- ### Collapsible (set) widget click to expand contents

  - Collapsible
  - Dynamic collapsibles
  - Collapsible set

- ### Controlgroup widget click to expand contents

  - Controlgroup
  - Dynamic controlgroups
- Datepicker

- ### Events click to expand contents

  - Swipe list items
  - Swipe page navigation
- Filterable widget
- Flipswitch widget

- ### Forms click to expand contents

  - Forms
  - Hide labels
  - Field containers
  - Forms disabled
  - Forms gallery

- ### Grids click to expand contents

  - Grids
  - Buttons in grids
  - Custom responsive grids
- Grouping and dividing content

- ### Icons click to expand contents

  - Icons
  - Grunticon loader

- ### Listview widget click to expand contents

  - Listview
  - Listview autocomplete
  - Listview autocomplete remote data
  - Listview autodividers linkbar
  - Listview autodividers selector
  - Nested Listviews
  - Listview collapsible list items (flat)
  - Listview collapsible list items (indented)
  - Listview responsive grid
- Loader widget
- Navbar widget

- ### Navigation click to expand contents

  - Navigation
  - Linking pages
  - Hash processing demo
  - Page Navigation Events

- ### Pages click to expand contents

  - Pages
  - Single page
  - Multi-page template
  - Dialog page

- ### Panel widget click to expand contents

  - Panel
  - External panels
  - Fixed panels
  - Panels responsive
  - Custom panel style
  - Panel open on swipe
  - Panel external and internal

- ### Popup widget click to expand contents

  - Popup
  - Popup alignment
  - Popup arrow size
  - Dynamic popups
  - Popups with iframes
  - Popup image scaling
  - Popup outside multi-page
- Rangeslider widget
- Responsive Web Design

- ### Selectmenu widget click to expand contents

  - Selectmenu
  - Custom select menu
  - Custom select menu with filter

- ### Slider widget click to expand contents

  - Slider
  - Slider flip toggle switch
  - Slider tooltip

- ### Table widget click to expand contents

  - Table Column Toggle
  - Table Column Toggle demo
  - Table Column Toggle heading groups
  - Table Column Toggle options
  - Table Reflow
  - Table Reflow heading groups
  - Table Reflow stripes and strokes
  - Table Reflow custom styles
- Tabs widget
- Textinput widget

- ### Theming click to expand contents

  - Default theme
  - Classic theme

- ### Toolbar widget click to expand contents

  - Toolbar
  - Dynamic toolbars
  - External toolbars
  - Fixed toolbars
  - Fullscreen toolbars
  - Fixed external toolbars
  - Persistent toolbars
  - Ajax optimized toolbars
  - Form in toolbar
- Transitions

- ### 3rd party API demos click to expand contents

  - Backbone RequireJS
  - Google Maps geolocation
  - Google Maps list toggle

- Home
- Introduction
- Buttons
- Button widget

- ### Checkboxradio widget click to expand contents

  - Checkboxes
  - Radio buttons

- ### Collapsible (set) widget click to expand contents

  - Collapsible
  - Dynamic collapsibles
  - Collapsible set

- ### Controlgroup widget click to expand contents

  - Controlgroup
  - Dynamic controlgroups
- Datepicker

- ### Events click to expand contents

  - Swipe list items
  - Swipe page navigation
- Filterable widget
- Flipswitch widget

- ### Forms click to expand contents

  - Forms
  - Hide labels
  - Field containers
  - Forms disabled
  - Forms gallery

- ### Grids click to expand contents

  - Grids
  - Buttons in grids
  - Custom responsive grids
- Grouping and dividing content

- ### Icons click to expand contents

  - Icons
  - Grunticon loader

- ### Listview widget click to expand contents

  - Listview
  - Listview autocomplete
  - Listview autocomplete remote data
  - Listview autodividers linkbar
  - Listview autodividers selector
  - Nested Listviews
  - Listview collapsible list items (flat)
  - Listview collapsible list items (indented)
  - Listview responsive grid
- Loader widget
- Navbar widget

- ### Navigation click to expand contents

  - Navigation
  - Linking pages
  - Hash processing demo
  - Page Navigation Events

- ### Pages click to expand contents

  - Pages
  - Single page
  - Multi-page template
  - Dialog page

- ### Panel widget click to expand contents

  - Panel
  - External panels
  - Fixed panels
  - Panels responsive
  - Custom panel style
  - Panel open on swipe
  - Panel external and internal

- ### Popup widget click to expand contents

  - Popup
  - Popup alignment
  - Popup arrow size
  - Dynamic popups
  - Popups with iframes
  - Popup image scaling
  - Popup outside multi-page
- Rangeslider widget
- Responsive Web Design

- ### Selectmenu widget click to expand contents

  - Selectmenu
  - Custom select menu
  - Custom select menu with filter

- ### Slider widget click to expand contents

  - Slider
  - Slider flip toggle switch
  - Slider tooltip

- ### Table widget click to expand contents

  - Table Column Toggle
  - Table Column Toggle demo
  - Table Column Toggle heading groups
  - Table Column Toggle options
  - Table Reflow
  - Table Reflow heading groups
  - Table Reflow stripes and strokes
  - Table Reflow custom styles
- Tabs widget
- Textinput widget

- ### Theming click to expand contents

  - Default theme
  - Classic theme

- ### Toolbar widget click to expand contents

  - Toolbar
  - Dynamic toolbars
  - External toolbars
  - Fixed toolbars
  - Fullscreen toolbars
  - Fixed external toolbars
  - Persistent toolbars
  - Ajax optimized toolbars
  - Form in toolbar
- Transitions

- ### 3rd party API demos click to expand contents

  - Backbone RequireJS
  - Google Maps geolocation
  - Google Maps list toggle