jQuery Mobile: 4-Column Grid-C

This entry is part 39 of 73 in the series jQuery Mobile

When designing an interface for a tablet, you might need a 4-column grid.

The 25/25/25/25% grid is created by specifying class=ui-grid-c on the parent and adding a fourth block.

Grid-C
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid C</h1></div>
    <br>
    <div class='ui-grid-c'>
        <div class='ui-block-a'><div class='ui-bar ui-bar-a' style='height:60px'>Block A</div></div>
        <div class='ui-block-b'><div class='ui-bar ui-bar-a' style='height:60px'>Block B</div></div>
        <div class='ui-block-c'><div class='ui-bar ui-bar-a' style='height:60px'>Block C</div></div>
        <div class='ui-block-d'><div class='ui-bar ui-bar-a' style='height:60px'>Block D</div></div>
    </div><!-- /grid-c -->

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

jQuery Mobile also supports 5-column grid.  This is done by using class=ui-grid-d.

jQuery Mobile: 3-Column Grid with Buttons

This entry is part 38 of 73 in the series jQuery Mobile

Now that we know how to create a 3-column grid, let’s put some buttons inside the grids.

3-Column Grid
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid B</h1></div>
    <br>
    <fieldset class='ui-grid-b'>
        <div class='ui-block-a'><input type='button' value='Hmm'></div>
        <div class='ui-block-b'><input type='reset' value='No'></div>
        <div class='ui-block-c'><input type='submit' value='Yes'></div>
    </fieldset>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

Grid classes can be applied to any container.

Here we are using fieldset tag to group together the buttons.

jQuery Mobile: Arranging 2 Buttons using Grid-A

This entry is part 37 of 73 in the series jQuery Mobile

Say we need to put 2 submit and reset buttons side by side on a page.

We can use grid-a to format the page.

2 Buttons in Grid
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid A</h1></div>
    <br>
    <div class='ui-grid-a'>
        <div class='ui-block-a'><input type='submit' value='Submit' data-theme='a'></div>
        <div class='ui-block-b'><input type='reset' value='Reset' data-theme='b'></div>
    </div>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

grid_a_buttons

Also, we have used 2 different themes for block a and block b.

jQuery Mobile: 3-column Grid B

This entry is part 36 of 73 in the series jQuery Mobile

Grid B is for 3-column block.

3-Column Grid
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid B</h1></div>
    <br>
    <div class='ui-grid-b'>
            <div class='ui-block-a'><div class='ui-bar ui-bar-a' style='height:60px'>Block A</div></div>
            <div class='ui-block-b'><div class='ui-bar ui-bar-a' style='height:60px'>Block B</div></div>
            <div class='ui-block-c'><div class='ui-bar ui-bar-a' style='height:60px'>Block C</div></div>
    </div><!-- /grid-a -->

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

gridB

As you can see, just by using class=’ui-grid-b’, we have turned the page into a 3-column block system.

jQuery Mobile: Grid

This entry is part 35 of 73 in the series jQuery Mobile

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

We look at a simple example below.

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.

2-Column Grid
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid A</h1></div>
    <div class='ui-grid-a'>
            <div class='ui-block-a'><div class='ui-bar ui-bar-a' style='height:60px'>Block A</div></div>
            <div class='ui-block-b'><div class='ui-bar ui-bar-a' style='height:60px'>Block B</div></div>
    </div><!-- /grid-a -->

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

gridA

This is the grid-a with a 2-column block.

In the next example, we will use grid-b which is for 3-column block.