Saturday, December 10, 2011

Apply grid layout on jQuery Mobile

To apply grid layout on jQuery Mobile, we can use ui-grid.

There are four preset configurations layouts that can be used in any situation that requires columns:
  • ui-grid-a : 2 column
  • ui-grid-b : 3 column
  • ui-grid-c : 4 column
  • ui-grid-d : 5 column


Within the grid container, child elements are assigned ui-block-a/b/c/d in a sequential manner which makes each "block" element float side-by-side, forming the grid.

Here is a example with 3 column grid:

jQuery Mobile with grid of 3 column

<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Button Icon</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Grid Layout</h1>
</div>
<div data-role="content">
<div class="ui-grid-b">
<div class="ui-block-a">
<a data-role="button" data-icon="arrow-l" >arrow-l</a>
<a data-role="button" data-icon="arrow-r" >arrow-r</a>
<a data-role="button" data-icon="arrow-u" >arrow-u</a>
<a data-role="button" data-icon="arrow-d" >arrow-d</a>
<a data-role="button" data-icon="delete" >delete</a>
<a data-role="button" data-icon="plus" >plus</a>
</div>
<div class="ui-block-b">
<a data-role="button" data-icon="minus" >minus</a>
<a data-role="button" data-icon="check" >check</a>
<a data-role="button" data-icon="gear" >gear</a>
<a data-role="button" data-icon="refresh" >refresh</a>
<a data-role="button" data-icon="forward" >forward</a>
<a data-role="button" data-icon="back" >back</a>
</div>
<div class="ui-block-c">
<a data-role="button" data-icon="grid" >grid</a>
<a data-role="button" data-icon="star" >star</a>
<a data-role="button" data-icon="alert" >alert</a>
<a data-role="button" data-icon="info" >info</a>
<a data-role="button" data-icon="home" >home</a>
<a data-role="button" data-icon="search" >search</a>
</div>
</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>

</div>

</body>
</html>

1 comment:

  1. Why Button text not Clearly visible. Now It show a...,. And How to make this visible like arrow-l

    ReplyDelete