concept grid system in category css

appears as: grid system, grid systems
CSS in Depth

This is an excerpt from Manning's book CSS in Depth.

As we go, you’ll also learn about two patterns that you might often see in page layouts: the double container pattern and the media object. To wrap up, you’ll put your knowledge to work to build a grid system, which is a versatile tool for structuring a page.

4.5.2. Building a grid system

Let’s convert your page so that it uses a grid system. This will prove to be a little more verbose than our previous approach to the page, but the tradeoff for more reusable CSS will be worth it. Edit your HTML to match this listing.

Listing 4.12. HTML restructured to use a grid system
<main class="main clearfix"> <h2>Running tips</h2> <div class="row"> 1 <div class="column-6"> 2 <div class="media"> <img class="media-image" src="runner.png"> <div class="media-body"> <h4>Strength</h4> <p> Strength training is an important part of injury prevention. Focus on your core&mdash; especially your abs and glutes. </p> </div> </div> </div> <div class="column-6"> 2 <div class="media"> <img class="media-image" src="shoes.png"> <div class="media-body"> <h4>Cadence</h4> <p> Check your stride turnover. The most efficient runners take about 180 steps per minute. </p> </div> </div> </div> </div> 3 <div class="row"> 1 <div class="column-6"> 2 <div class="media"> <img class="media-image" src="shoes.png"> <div class="media-body"> <h4>Change it up</h4> <p> Don't run the same every time you hit the road. Vary your pace, and vary the distance of your runs. </p> </div> </div> </div> <div class="column-6"> 2 <div class="media"> <img class="media-image" src="runner.png"> <div class="media-body"> <h4>Focus on form</h4> <p> Run tall but relaxed. Your feet should hit the ground beneath your hips, not out in front of you. </p> </div> </div> </div> </div> </main>

At this stage, you’ve got the basics of a grid system in place. Your page should look like figure 4.17. It looks a bit broken at this point because the media objects still have some styles that are duplicating the work done by the grid system.

Figure 4.17. With the grid system applied, the media objects no longer need some of their styles.