HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
@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;
}
Also see: Tab Triggers