jQuery Mobile - Listview Responsive Grid



Description

The style is adjusted using the class ui-li-has-thumb. It makes the image size as same as of the tiles in the grid layout.

Example

Following example demonstrates the use of responsive grid listview in the jQuery Mobile.

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <link rel = "stylesheet" href = "http://demos.jquerymobile.com/1.4.5/listview-grid/listview-grid.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/jquery-1.11.3.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>
   
   <body>
      <div data-role = "page" data-theme = "a" class = "my-page" id = "demo-page">
         <div data-role  =  "header">
            <h2>Responsive Grid Example</h2>
         </div>
         
         <div role = "main" class = "ui-content">
            <ul data-role = "listview" data-inset = "true">
               <li><a href = "#">
                  <img src = "/jquery_mobile/images/apple.jpg" class = "ui-li-thumb">
                  <h2>Fruits</h2>
                  <p>Apple</p>
                  <p class = "ui-li-aside">Apple</p></a>
               </li>
               
               <li><a href = "#">
                  <img src = "/jquery_mobile/images/cherry.jpg" class = "ui-li-thumb">
                  <h2>Fruits</h2>
                  <p>Cherry</p>
                  <p class = "ui-li-aside">Cherry</p></a>
               </li>
               
               <li><a href = "#">
                  <img src = "/jquery_mobile/images/grapes.jpg" class = "ui-li-thumb">
                  <h2>Fruits</h2>
                  <p>Grapes</p>
                  <p class = "ui-li-aside">Grapes</p></a>
               </li>
               
               <li><a href = "#">
                  <img src = "/jquery_mobile/images/watermelon.jpg" class = "ui-li-thumb">
                  <h2>Fruits</h2>
                  <p>Watermelon</p>
                  <p class = "ui-li-aside">Watermelon</p></a>
               </li>
            </ul>
         </div>
      </div>
   </body>
</html>

Output

Let's carry out the following steps to see how the above code works −

  • Save the above html code as listview_responsive_grid.html file in your server root folder.

  • Open this HTML file as http://localhost/listview_responsive_grid.html and the following output will be displayed.

jquery_mobile_widgets.htm
Advertisements