Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 2.19 KB

basic-layout.md

File metadata and controls

55 lines (35 loc) · 2.19 KB

Basic Layout

There are several techniques to lay out content. Even though there are now advanced techniques to handle almost every scenario, there are some more basic ones, that will be suited for a good variety of scenario, without the hassle of a more advanced tools, like flexbox.

Some of the basic ones are:

  1. Float Layout
  2. Inline Layout
  3. Positioned Layout

Float layout

Layouting with float is maybe the most commonly used method. It's pretty easy to understand but it has some twists, as the floated elements needs to be cleared to maintaing the page flow. Thankfully we have a technique to deal with the problem called clearfix.

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}   

It may seem a little abstract, but what this does is it forces a parent element to clear for it's childrens. Take a look at the snippet to see how it's used and check this link for more information: https://css-tricks.com/snippets/css/clear-fix/

Example

Demo: http://codepen.io/Vratyas/pen/zGdWYO
Gist: https://gist.github.com/Vratyas/bc14a63bbf2315ff2fa3

Inline layout

Layouting with inline blocks is more rare but it's an option. The problem with it it's that the blocks themself tend to add a subtle margin wich can mess with the flow. There are many techniques to deal with this problem.

<div class="grid">
  <div class="square"></div><!--
  --><div class="square"></div><!--
  --><div class="square"></div><!--
  --><div class="square"></div>
</div>

We opted for the 'comment' technique for our snippets but check this article and choose the on that fits your project best: https://css-tricks.com/fighting-the-space-between-inline-block-elements/

Example

Demo: http://codepen.io/Vratyas/pen/vOJRee
Gist: https://gist.github.com/Vratyas/3c13837cd8050628a20f

Positioned layout

Example

Demo: http://codepen.io/Vratyas/pen/KpvogJ
Gist: https://gist.github.com/Vratyas/ea703168f7642dd0a897

Credits

email: Juan Fernandez j.fernandez@globant.com