cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <header>
    <h2>Simple 'holy grail' layout</h2>
  </header>

  <div class="right-col">
    <div class="center-col">
      <div class="left-col">
        <article class="center">
          <h3>When divs Attack.</h3>
          <p>Semantically, I'm a fan of something I heard in an FITC conference I attended a few years back. </p>
          <blockquote>If you're nesting your HTML more than 3 divs deep, you're doing it wrong.</blockquote>
          <p>I'd amend that to up to 5 now, having worked with Angular apps and around their requirements, as well as with complex site layouts. Keeping it to 3 is great, until you have to do something like this layout.</p>
    
          <p>This is a great flexible, % based layout that's pretty hard to screw up. It's entirely inspired by <a href="http://matthewjamestaylor.com/blog/perfect-3-column.htm" target="_blank">Matthew James Taylor</a>, with some additions for mobile layout first. I've added all the things in a media query to keep mobile simple; no one needs to define all that and then hide it for mobile. That's insanity.</p>
    
          <p>If you didn't come from the Flex version of this, look to your right (not in the room, over there in the column), and find a link to it. </p>
        </article>
 
        <aside class="left">
          Look ma, short text!
        </aside>
    
        <aside class="right">
          <p>Flex version of this layout. A bit more risky especially in older browsers, but feeds the semantic OCD in me:</p>
          <p><a href="https://codepen.io/fay-lisa/pen/ZpGvzL" target="_blank">Flex magicks</a>
        </aside>
      </div>
    </div>
  </div>

  <footer>
    <ul> 
      <li>
       This will work in everything. Even iPad, iPhone, and *gasp* IE theoretically down to 7. Hide your children.
     </li>
    </ul>
  </footer>
</div>
            
          
!
            
              // relatively simple 3 column holy grail layout, with nearly unlimited support in browser and mobile
.container {
  width: 100%;
  
  // add styling for each section for mobile: 
  header {
    background: #b6b6b6;
  }
  
  .left {
    background: #c6c5c3; // making this a bit darker on mobile so the columns have separation without borders
  }

  .center {
    background: #e2e1dd;
  }
    
  .right {
    background: #d5d3d0;
  }
  
  footer {
    background: #c6c5c3;
  }
  
  // shared padding for mobile
  header, footer, article, aside {
    width: 100%;
    padding: 10px;
  }

  
  // now we change layout for larger than phone screens (ipad, ipad mini, larger phablets)
  @media all and (min-width: 600px) {
    
    .right-col {
      clear: both;
      overflow: hidden;
    }
    
    // elements all the 'column' containers share: 
    .right-col,
    .center-col,
    .left-col {
      width: 100%;
      float: left;
		  position: relative;
    }
    
    .right-col {
      background: #d5d3d0; // colors the right column in the end
    }
    
    .center-col {
      right: 20%;
      background: #e2e1dd; // colors the center column in the end
    }
    
    .left-col {
      right: 60%;
      background: #d5d3d0; // colors the left column in the end
    }
    
    .center, .left, .right {
      float: left;
		  position: relative;
      background: transparent; // this gets rid of the mobile bkgs, as they now use the new magic for ipad and up
      padding: 10px 0;
    }
    
    .center {
      width: 55%; // width of the center column content
		  left: 101%;
    }
    
    .left {
      width: 18%; // width of the left column content
		  left: 26%;	
    }
    
    .right {
      width: 18%; // width of the right column content
		  left: 88%;
    }
    
    footer {
      clear: both;
    }
  }
}


// basic styling. 
body {
  font-family: Helvetica, Arial, sans-serif;
  background: aliceblue;
  line-height: 19px;
}
* {
  box-sizing: border-box;
}
//a tags 
a {
  color: #ab0d58;
  padding: 2px;
}
h2, footer {
  text-align: center;
}
h2 {
  margin: 0;
  padding: 30px 0;
}
h3 {
  margin: 0 0 10px 0;
}
p {
  margin: 5px 0 20px;
}
ul {
  // getting rid of the browser default
  margin: 0;
  padding: 0;
  list-style-type: none;
  
  li {
    margin: 10px 5px;
    display: inline-block;
    padding: 5px;
  }
}
blockquote {
  background: #d5d3d0;
  padding: 20px;
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console