How to create a grid layout on a webpage using jQuery Mobile
Overview
The jQuery Mobile framework defines CSS classes that let us create a grid layout on a webpage. This is a simple way to create a responsive grid layout.
Code
We create an HTML page and use jQuery Mobile to make a grid layout on it.
Explanation
-
Line 4–6: We include jQuery on our webpage.
-
Line 11: We create a container using
divand classui-grid-b. This class creates a container with 3 divisions of 33.3% each on the page. The classui-grid-bis changed if we need more columns. For 2 columns, we use the classui-grid-a. For 3 columns, we use the classui-grid-b, and so on. -
Line 12: This
divis the first block of the screen. We create a childdivelement with the classui-block-a. This class tells us that thedivis in the first block. The other childdiv, with classesui-barandui-bar-a, gives a style to our current block. -
Line 13: This
divrepresents the middle block of the screen. We need to add classui-block-bto thisdiv, which makes it the second column of the screen with a width of 33.3%. -
Line 14: This
divrepresents the last block of the screen. We need to add classui-block-cto thisdiv, which makes it the third column of the screen with a width of 33.3%.
Result
When we render this HTML, we see that the webpage is divided into three columns, which is the grid layout.