What is a Grid-View?
Many web pages are based on a grid-view, which means that the page is divided into rows and columns.
Using a grid-view is very helpful when designing web pages. It makes it easier to place elements on the page.
A responsive grid-view often has 6 or 12 columns, and will shrink and expand as you resize the browser window.
Building a Grid View
Lets start building a grid-view.
First ensure that all HTML elements have the box-sizing
property set to border-box
. This makes sure that the padding and border are included in the total width and height of the elements.
Add the following at the begnning of your CSS :
* {
margin: 0;
box-sizing: border-box;
}
Read more about the box-sizing
property in our CSS Box Sizing chapter.
The HTML
We create a grid container with five grid items (item1 = Header, item2 = Menu, item3 = Main content, item4 = right, item5 = Footer):
HTML
Here is the complete HTML:
<div class="grid-container">
<div class="item1">
<h1>Chania</h1>
</div>
<div class="item2">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="item3">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete.</p>
<p>The city can be divided in two parts, the old town and the modern city. The old town is situated next to the old harbour and is the matrix around which the whole urban area was developed.</p>
<p>Chania lies along the north west coast of the island Crete.</p>
</div>
<div class="item4">
<h2>Facts:</h2>
<ul>
<li>Chania is a city on the island of Crete</li>
<li>Crete is a Greek island in the Mediterranean Sea</li>
</ul>
</div>
<div class="item5">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</div>