Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>A comparison of media object and flag object</h1>

<p>This is a small demo and comparison of the <a href="http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/">media object</a> made popular by Nicole Sullivan, aka <a href="https://twitter.com/stubbornella">@stubbornella</a>, and the <a href="https://csswizardry.com/2013/05/the-flag-object/">flag object</a> by Harry Roberts - the guy behind <a href="https://twitter.com/csswizardry">@csswizardry</a>.</p>

<p>Both UI patterns are commonly used on the web today. Simple as they may seem, coding them with flexibility in mind, can in fact be quite challenging. Here I've tried to compare the two techniques.</p>

<h2>The media object by <a href="https://twitter.com/stubbornella">@stubbornella</a></h2>

<p>The media object is an image to the left, with descriptive content to the right, often seen on Facebook. The content area on the right can contain any other objects. In this case, it contains text, but we could put lists, grids, or even other media objects inside. As we’ve seen before, there are actually many different versions of the media block on the Facebook website (and on most websites).</p>

<p>The hard part is making sure that the image can be any width, so that the element is reusable. It means our content area needs to be flexible so that it can fill in all the remaining space available. It is a very simple object, but it is very powerful.</p>

<div class="media">
  <a href="http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/" class="media__img">
    <img src="https://s.cdpn.io/13060/megaman_72x72.png" alt="Megaman" />
  </a>
  <div class="media__body">
    <p><strong>This is a media object</strong></p>
    <p>Bacon ipsum dolor sit amet shankle swine cow, shoulder brisket pork belly leberkas tail ham shank beef ribs. Shankle jowl brisket beef filet mignon ribeye frankfurter pork loin tongue short ribs corned beef venison tenderloin. Pork loin swine hamburger, turducken tail boudin shoulder doner pig flank meatloaf ham pancetta t-bone shank.</p>
    <p>Drumstick biltong tenderloin bacon, ball tip shankle chicken short loin salami venison beef kielbasa pork loin shoulder. Meatball cow ham ribeye.</p>
  </div>
</div>

<h2>The flag object by <a href="https://twitter.com/csswizardry">@csswizardry</a></h2>

<p>However, as awesome as the media object is, there is one thing it can’t (and was probably never designed to) do well; vertical alignment. Oftentimes it’s desirable to have the image content and text content aligned to their vertical middles. The only way to achieve this kind of thing with the media object would be by using margins and paddings and magic numbers.</p>

<p>The flag object shares a lot of common traits with the media object. Where the flag object differs, however, is its ability to vertically align the image and text to the tops, middles or bottoms of each other.</p>

<p>One thing to note is that the flag object is slightly more verbose in its implementation; the media object can have its classes applied directly to its content whereas the flag object needs its classes applied to wrappers around its content.</p>

<div class="flag">
  <a href="https://csswizardry.com/2013/05/the-flag-object/" class="flag__image">
    <img src="https://s.cdpn.io/13060/megaman_72x72.png" alt="Megaman" />
  </a>
  <div class="flag__body">
    <p><strong>This is a flag object (vertical-align: middle)</strong></p>
    <p>Bacon ipsum dolor sit amet shankle swine cow, shoulder brisket pork belly leberkas tail ham shank beef ribs. Shankle jowl brisket beef filet mignon ribeye frankfurter pork loin tongue short ribs corned beef venison tenderloin. Pork loin swine hamburger, turducken tail boudin shoulder doner pig flank meatloaf ham pancetta t-bone shank.</p>
    <p>Drumstick biltong tenderloin bacon, ball tip shankle chicken short loin salami venison beef kielbasa pork loin shoulder. Meatball cow ham ribeye.</p>
  </div>
</div>

<div class="flag flag--top">
  <a href="https://csswizardry.com/2013/05/the-flag-object/" class="flag__image">
    <img src="https://s.cdpn.io/13060/megaman_72x72.png" alt="Megaman" />
  </a>
  <div class="flag__body">
    <p><strong>This is a flag object (vertical-align: top)</strong></p>
    <p>Bacon ipsum dolor sit amet shankle swine cow, shoulder brisket pork belly leberkas tail ham shank beef ribs. Shankle jowl brisket beef filet mignon ribeye frankfurter pork loin tongue short ribs corned beef venison tenderloin. Pork loin swine hamburger, turducken tail boudin shoulder doner pig flank meatloaf ham pancetta t-bone shank.</p>
    <p>Drumstick biltong tenderloin bacon, ball tip shankle chicken short loin salami venison beef kielbasa pork loin shoulder. Meatball cow ham ribeye.</p>
  </div>
</div>

<div class="flag flag--bottom">
  <a href="https://csswizardry.com/2013/05/the-flag-object/" class="flag__image">
    <img src="https://s.cdpn.io/13060/megaman_72x72.png" alt="Megaman" />
  </a>
  <div class="flag__body">
    <p><strong>This is a flag object (vertical-align: bottom)</strong></p>
    <p>Bacon ipsum dolor sit amet shankle swine cow, shoulder brisket pork belly leberkas tail ham shank beef ribs. Shankle jowl brisket beef filet mignon ribeye frankfurter pork loin tongue short ribs corned beef venison tenderloin. Pork loin swine hamburger, turducken tail boudin shoulder doner pig flank meatloaf ham pancetta t-bone shank.</p>
    <p>Drumstick biltong tenderloin bacon, ball tip shankle chicken short loin salami venison beef kielbasa pork loin shoulder. Meatball cow ham ribeye.</p>
  </div>
</div>

<div class="flag flag--rev">  
  <div class="flag__body">
    <p><strong>This is a flag object (reversed)</strong></p>
    <p>Bacon ipsum dolor sit amet shankle swine cow, shoulder brisket pork belly leberkas tail ham shank beef ribs. Shankle jowl brisket beef filet mignon ribeye frankfurter pork loin tongue short ribs corned beef venison tenderloin. Pork loin swine hamburger, turducken tail boudin shoulder doner pig flank meatloaf ham pancetta t-bone shank.</p>
    <p>Drumstick biltong tenderloin bacon, ball tip shankle chicken short loin salami venison beef kielbasa pork loin shoulder. Meatball cow ham ribeye.</p>
  </div>
  <a href="https://csswizardry.com/2013/05/the-flag-object/" class="flag__image">
    <img src="https://s.cdpn.io/13060/megaman_72x72.png" alt="Megaman" />
  </a>
</div>
              
            
!

CSS

              
                @import "compass/css3";

/* ====== MEDIA OBJECT ====== */
/* URL: http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/

*/
.media {
  margin:10px;
}

.media, .media__body {
  overflow:hidden;
  _overflow:visible;
  zoom:1;
}

.media .media__img {
  float:left;
  margin-right: 10px;
}

.media .media__img img{
  display:block;
}

.media .imgExt{
  float:right;
  margin-left: 10px;
}

/* ====== FLAG OBJECT ====== */
/* URL: https://csswizardry.com/2013/05/the-flag-object/ */

.flag{
  display:table;
  width:auto;
  margin:10px;
}

.flag__image, .flag__body{
  display:table-cell;
  vertical-align:middle;
  
  .flag--top &{
    vertical-align:top;
  }
  
  .flag--bottom &{
    vertical-align:bottom;
  }
}

.flag__image{
  padding-right:10px;
  
  > img{
    display:block;
  }
  
  .flag--rev &{
    padding-right:0;
    padding-left:10px;
  }
}

.flag__body{
  width:100%;
}



/* Common styling for demo purposes */

body{
  width: 70%;
  padding: 20px;  
  margin: 0 auto;  
  box-shadow: 0px 0px 10px 3px rgba(0,0,0,0.3);
}

.media, .flag{
  background: #f5f5f5;
  border :1px solid #d5d5d5;
  padding: 10px;
}

p{
  margin-top: 0;
}

              
            
!

JS

              
                
              
            
!
999px

Console