JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div class="latest-posts">
<h3 class="latest-posts-title">Latest posts - The complicated way with borders and an ad inserted</h3>
<div class="latest-posts-items">
<article class="post">
<h3 class="post-title">The title of the post #1</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #1.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #2</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #2.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #3</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #3.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #4</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #4.
</div>
</article>
<div class="ad-container">
<div class="ad">The ad is inserted here</div>
</div>
<article class="post">
<h3 class="post-title">The title of the post #5</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #5.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #6</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #6.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #7</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #7.
</div>
</article>
<article class="post">
<h3 class="post-title">The title of the post #8</h3>
<figure class="post-featured-image">
<img src="https://via.placeholder.com/350x150"/>
</figure>
<div class="post-excerpt">
This is a short description (a.k.a excerpt) of around a few dozens of characters associated with and for the post #8.
</div>
</article>
</div>
</div>
// Drawing borders for the flexbox grid
@mixin flexbox-grid-borders($items-per-row, $margin-right: 0, $grid-title: false) {
> * {
border-right: 1px solid gray;
@if ($margin-right != 0) {
padding-right: calc(#{$margin-right} / 2);
margin-right: calc(#{$margin-right} / 2);
}
}
// Right margins
@if ($grid-title == true) {
> *:not(h3) {
&:nth-child(#{$items-per-row}n + 1) {
border-right: 0;
padding-right: 0;
}
}
} @else {
> * {
&:nth-child(#{$items-per-row}n) {
border-right: 0;
padding-right: 0;
}
}
}
}
// A flexbox grid with margins / column gap set manually
@mixin flexbox-grid(
$items-per-row,
$margin-right: 0,
$margin-bottom: 0,
$max-items-to-display: null,
$grid-title: false,
$iepx: 0px
) {
$item-width: percentage(1 / $items-per-row);
$item-flex-basis: calc(
#{$item-width} - (((#{$items-per-row} - 1) * #{$margin-right}) / #{$items-per-row * 2}) - #{$iepx}
);
display: flex;
flex-direction: row;
flex-wrap: wrap;
> * {
// Now we can have padding and border for items
box-sizing: border-box;
margin-bottom: $margin-bottom;
margin-right: $margin-right;
// Only $max-items-to-display number of items will be shown
@if ($max-items-to-display != null) {
display: none;
@for $i from 0 through $max-items-to-display - 1 {
&:nth-child(#{$i + 1}) {
display: flex;
}
}
}
}
// Right margins
@if ($grid-title == true) {
> *:not(h3) {
width: $item-flex-basis;
&:nth-child(#{$items-per-row}n + 1) {
margin-right: 0;
}
}
} @else {
> * {
width: $item-flex-basis;
&:nth-child(#{$items-per-row}n) {
margin-right: 0;
}
}
}
}
// A responsive grid with flexbox
@mixin responsive-flexbox-grid(
$margin-right: 0,
$margin-bottom: 0,
$borders: true,
$max-items-to-display-map: null
) {
@media (max-width: 767px) {
$max-items-to-display: map-get($max-items-to-display-map, mobile);
@include flexbox-grid(1, $margin-right, $margin-bottom, $max-items-to-display);
@include flexbox-grid-borders(1, $margin-right);
}
@media (min-width: 768px) and (max-width: 959px) {
$max-items-to-display: map-get($max-items-to-display-map, tablet);
@include flexbox-grid(2, $margin-right, $margin-bottom, $max-items-to-display);
@include flexbox-grid-borders(2, $margin-right);
}
@media (min-width: 960px) and (max-width: 1279px) {
$max-items-to-display: map-get($max-items-to-display-map, laptop);
@include flexbox-grid(3, $margin-right, $margin-bottom, $max-items-to-display);
@include flexbox-grid-borders(3, $margin-right);
}
@media (min-width: 1280px) {
$max-items-to-display: map-get($max-items-to-display-map, desktop);
@include flexbox-grid(4, $margin-right, $margin-bottom, $max-items-to-display);
@include flexbox-grid-borders(4, $margin-right);
}
}
// A special mixin to regrid posts for the ad
@mixin latest-posts--regrid-for-ad($max-items-to-display-map, $margin-right) {
.ad-container {
width: 100%;
}
@media (max-width: 767px) {
$max-items-to-display: map-get($max-items-to-display-map, mobile);
$half: round($max-items-to-display / 2);
> * {
@for $i from 1 to 9 {
&:nth-child(#{$i}) {
@if ($i < $half) {
order: #{$i};
}
@if ($i > $half) {
order: #{$i + 1};
}
@if ($i == 5) {
order: #{$half};
}
}
}
}
}
@media (min-width: 768px) and (max-width: 959px) {
$max-items-to-display: map-get($max-items-to-display-map, tablet);
$half: round($max-items-to-display / 2);
> * {
@for $i from 1 to 9 {
&:nth-child(#{$i}) {
@if ($i < $half) {
order: #{$i};
}
@if ($i >= $half) {
order: #{$i + 1};
}
@if ($i == 5) {
order: #{$half};
}
}
}
}
}
@media (min-width: 960px) and (max-width: 1279px) {
$max-items-to-display: map-get($max-items-to-display-map, laptop);
$half: round($max-items-to-display / 2);
> * {
@for $i from 1 to 9 {
&:nth-child(#{$i}) {
@if ($i < $half) {
order: #{$i};
}
@if ($i >= $half) {
order: #{$i + 1};
}
@if ($i == 5) {
order: #{$half};
}
@if ($i == 6) {
margin-right: calc(#{$margin-right} / 2);
padding-right: calc(#{$margin-right} / 2);
border-right: 1px solid gray;
}
@if ($i == 7) {
margin-right: 0;
padding-right: 0;
border: none;
}
}
}
}
}
@media (min-width: 1280px) {
$max-items-to-display: map-get($max-items-to-display-map, desktop);
$half: round($max-items-to-display / 2);
> * {
@for $i from 1 to 10 {
&:nth-child(#{$i}) {
order: #{$i};
display: flex;
@if ($i == 8) {
margin-right: calc(#{$margin-right} / 2);
padding-right: calc(#{$margin-right} / 2);
border-right: 1px solid gray;
}
@if ($i == 9) {
margin-right: 0;
padding-right: 0;
border: none;
}
}
}
}
}
}
// Styling posts
@mixin post {
flex-direction: column;
figure {
margin: 0;
img {
max-width: 100%;
height: auto;
}
}
}
// Styling the ad
@mixin ad-container {
display: flex;
justify-content: center;
.ad {
background-color: black;
color: white;
width: 728px;
height: 90px;
display: flex;
justify-content: center;
align-items: center;
@media (max-width: 767px) {
width: 300px;
height: 250px;
}
}
}
// The main styling
.latest-posts {
display: grid;
.latest-posts-items {
$max-items-to-display-map: (
mobile: 2,
tablet: 5,
laptop: 7,
desktop: 9
);
@include responsive-flexbox-grid(1.25em, 1.25em, true, $max-items-to-display-map);
@include latest-posts--regrid-for-ad($max-items-to-display-map, 1.25em);
.post {
@include post;
}
.ad-container {
@include ad-container;
}
}
}
Also see: Tab Triggers