CodePen

HTML

            
              <div class="module">
  <h3>Spacing the Bottom of Modules</h3>
  <p>Using pseudo elements <code>::before</code> and <code>::after</code> you can add consistent padding to an element without modifying children elements.</p>
  <p>In response to: <a href="http://css-tricks.com/spacing-the-bottom-of-modules/"><strong>CSS Tricks:</strong> Spacing the Bottom of Modules</a></p>
</div>

<div class="module">
  <p>Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum id ligula porta felis euismod semper. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec ullamcorper nulla non metus auctor fringilla.</p>
</div>

<div class="module">
  <img src="http://placehold.it/300" alt="Just a nice placeholder image" />
</div>

<div class="module">
  <p>Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum id ligula porta felis euismod semper. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec ullamcorper nulla non metus auctor fringilla.</p>
  <p>Etiam porta sem malesuada magna mollis euismod. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ullamcorper nulla non metus auctor fringilla. Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p>
</div>
            
          
!
via HTML Inspector

CSS

            
              // ----------------------------------------------------------
// So I heard you like to see the spacing in between elements
// ----------------------------------------------------------

:hover {
  outline: 1px solid rgba(red, 0.5);
  outline-offset: -1px;
}

// -------------------------
// Those sweet module styles
// -------------------------

.module {
  background: #eee;
  margin: 20px 0;
  padding: 0 20px;
  
  &::before,
  &::after {
    content: "";
    display: block;
    height: 1px;
  }
  
  &:before {
    margin-bottom: 19px;
  }
    
  &:after {
    margin-top: 19px;
  }
}

// -----------------------    
// A Wild Mixin Appears...
// -----------------------
    
@mixin module-padding($padding) {
  padding: 0 $padding;
  
  &::before,
  &::after {
    content: "";
    display: block;
    height: 1px;
  }
  
  &:before {
    margin-bottom: $padding - 1;
  }
    
  &:after {
    margin-top: $padding - 1;
  }
}

// -----------------------------------------    
// Just some typical everyday content styles
// -----------------------------------------

body {
  margin: 20px;
  font: normal 1em/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

img {
  vertical-align: top;
  max-width: 100%;
  height: auto;
}
  
h3 {
  margin: 20px 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ccc;
}
            
          
!
? ?
? ?
Must be a valid URL.
+ add another resource
via CSS Lint

JS

            
              
            
          
!
Must be a valid URL.
+ add another resource
via JS Hint
Loading ..................