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

              
                %button.night-button
%header
  %h1 Randomising Flex Order of Items
  %p Just a random thing where my colleague said "it'd be really good if we could do this", so I did.
%main
  %h2 Showing first of all that the randomisation can be done.
  %button.randomise-button Re-randomise
  .container
    -# Change the numbers in the range below (1..25) to see the results!
    - (1..25).each do |i|
      %div.item{:id => "item-#{i}"} #{i}
  %h2 Actual Application
  %p This is where we had a range of vendor logos to choose from, but only had room to display a certain subset of them depending on screen size, and of course we didn't want them to always be the same ones - someone viewing on a mobile might think we supply kit from 3 different vendors and that's it!
  %button.randomise-button Re-randomise
  .container-app
    - (1..25).each do |i|
      %div.item{:id => "item-#{i}"} #{i}
  %p You will notice that the above row still displays random numbers between the 2 numbers you have chosen, (if you're in the full view on CodePen, it defaults to 1 and 25) but it only displays a subset of them, using overflow: hidden to hide the rest.
%footer
  %p Gavin Sykes 2020
              
            
!

CSS

              
                $white: #eef;
$black: #080808;

* {
  font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;
  box-sizing: border-box;
}

html {
  padding: 0;
  color: $black;
  background-color: $white;
  min-height: 100vh;
  max-width: 100vw;
}
body {
  margin: 0;
  padding: 0;
  max-width: 100vw;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  grid-template-columns: 1fr;
  grid-template-areas:
    "header"
    "nav"
    "main"
    "footer";
  &.night {
    color: $white;
    background-color: $black;
  }
}
.night-button {
  position: fixed;
  bottom: 0;
  right: 0;
  font-weight: bold;
  background-color: $black;
  color: $white;
  border: none;
  padding: 1rem;
  border-top-left-radius: 1rem;
}
.night .night-button {
  background-color: $white;
  color: $black;
}
header {
  grid-area: header;
  padding: 0.5rem;
}
main {
  grid-area: main;
  padding: 0.5rem;
}
footer {
  grid-area: footer;
  padding: 0.5rem;
}
.container {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-around;
}
.container-app {
  @extend .container;
  height: 110px;
  overflow: hidden;
}
.randomise-button {
  border-radius: 1rem;
  border: none;
  padding: 1rem;
  background-color: orange;
  color: $black;
  margin: 10px;
  text-align: center;
}
.night .randomise-button {
  background-color: darkred;
}
.item {
  @extend .randomise-button;
  width: 100px;
  height: 100px;
  padding: 0;
  font-weight: 700;
  font-size: 3rem;
  color: $white;
}
.night .item {
  color: $black;
  background-color: darkred;
}
              
            
!

JS

              
                /* --- NIGHT MODE FUNCTIONS --- */
const keyElems = {
  html        : document.querySelector('body'),
  nightButton : document.querySelector('.night-button')
};
function toggleNight() {
  setNight(!isNight());
}
const isNight = () => keyElems.html.classList.contains('night');
function setNight(night) {
  if (night) {
    keyElems.html.classList.add('night');
    keyElems.nightButton.textContent = `Day Mode`;
  } else {
    keyElems.html.classList.remove('night');
    keyElems.nightButton.textContent = `Night Mode`;
  }
}
function checkNightOnLoad() {
  let h = new Date().getHours();
  if (h < 7 || h > 18) {
    setNight(true);
  } else {
    setNight(false);
  }
}
checkNightOnLoad();
keyElems.nightButton.addEventListener('click',toggleNight);
/* --- END OF NIGHT MODE FUNCTIONS --- */

class nightMode {
  constructor(els) {
    this.html = els.html;
    this.nightButton = els.nightButton;
  }
}

const randomiseFlexOrder = querySelector => {
  [...querySelector].map((c,i,a) => c.style.order = Math.floor(Math.random() * a.length + 1));
};
randomiseFlexOrder(document.querySelectorAll('.item'));
Array.from(document.querySelectorAll('.randomise-button')).map(i => i.addEventListener('click',() => randomiseFlexOrder(document.querySelectorAll('.item'))));
              
            
!
999px

Console