RWD Grid View


What is a Grid-View?

Most websites use a grid layout, where the webpage is split into columns:


Grid-views are handy for creating web pages because they simplify the process of arranging elements on the page.


A responsive grid usually has 12 columns and takes up the whole width of the webpage, which is 100%. It adjusts in size as you make the browser window smaller or larger.


Building a Responsive Grid-View

Let's begin creating a grid that adjusts itself to different screen sizes.

To start, make sure that all HTML elements have their "box-sizing" property set to "border-box." This ensures that both the padding and border are counted as part of the element's overall width and height.

Please include this code in your CSS file:

* {
  box-sizing: border-box;
}

You can learn more about the "box-sizing" property by visiting our CSS Box Sizing chapter at this link: CSS Box Sizing.

Here's an example of a basic web page that adjusts its layout to fit different screen sizes. This page has two columns.

25%
75%

The example is good if the webpage has only two columns.

Sure, we'd like to use a flexible grid layout with 12 columns to have better control over how our webpage looks.

To find the percentage for a single column, we divide 100% by 12 columns, which equals 8.33%.

We create a separate class for each of the 12 columns, using the "col-" class and a number to determine how many columns the section should cover.

All these columns should be on the left side and have 15 pixels of space around them.

We'd like to enhance its appearance with some stylish colors and designs.

Notice that the webpage in the example does not look good when you resize the browser window to a very small width. In the next chapter you will learn how to fix that.

We also want to make it look nicer by adding some styles and colors: