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.
<header>
<nav>
<a href="#">Super App 3000</a>
<ul class="menu">
<li>Choose Grid Layout:</li>
<li>
<button class="is-current js-layout-button" type="button" data-layout-toggle="1">
Three columns
</button>
</li>
<li>
<button class="js-layout-button" type="button" data-layout-toggle="2">
Two columns
</button>
</li>
<li>
<button class="js-layout-button" type="button" data-layout-toggle="3">
One column
</button>
</li>
</ul>
</nav>
</header>
<main class="grid js-grid" data-layout="1">
<div id="module_1"><span>1</span></div>
<div id="module_2"><span>2</span></div>
<div id="module_3"><span>3</span></div>
</main>
<footer>
<p>
© #currentyear –
<a href="https://www.bshow.co/">Bobby Showalter</a>
</p>
</footer>
/**
* Grid Layout magic!
*/
@media screen and (min-width: 60rem) {
/* parent grid settings */
.grid {
display: grid;
align-items: start;
grid-column-gap: 1rem;
}
/* layout 1 styles */
.grid[data-layout="1"] {
grid-template: min-content / 15rem 1fr 15rem;
}
/* layout 2 styles */
.grid[data-layout="2"] {
grid-template: repeat(2, min-content) / 1fr 15rem;
}
.grid[data-layout="2"] #module_1 {
grid-area: 1 / 1 / 2 / 2;
}
.grid[data-layout="2"] #module_2 {
grid-area: 2 / 1 / 3 / 2;
}
.grid[data-layout="2"] #module_3 {
grid-area: 1 / 2 / 3 / 3;
}
/* layout 3 styles */
.grid[data-layout="3"] {
grid-template: repeat(3, min-content) / 100%;
}
}
/**
* Beautification stuff
*/
/* |Variables */
:root {
/* colors */
--c-white: #fbfbfb;
--c-light-gray: #dfe6e9;
--c-gray: #b2bec3;
--c-shadow: #636e7255; /* #rrggbbaa */
--c-text: #2d3436;
--c-red: #d6303155;
--c-green: #00b89455;
--c-blue: #0984e355;
}
/* |Styles */
html {
background-color: var(--c-light-gray);
box-sizing: border-box;
color: var(--c-text);
font-family: 'Work Sans', sans-serif;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
html,
body {
height: 100%;
}
body {
display: grid;
grid-template-rows: min-content 1fr min-content;
}
header,
footer {
background-color: var(--c-gray);
border: 2px solid var(--c-shadow);
}
footer p {
margin: 0;
padding: 1rem;
}
footer p a {
color: var(--c-text);
font-weight: 700;
}
nav {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
}
nav a {
color: var(--c-text);
font-size: 1.5rem;
font-weight: 700;
}
.menu {
display: flex;
align-items: center;
list-style: none;
margin: 0;
padding-left: 0;
}
.menu li + li {
margin-left: 1rem;
}
.menu button {
background: transparent;
border: 1px solid var(--c-text);
border-radius: 3px;
color: var(--c-text);
font-family: inherit;
padding: .25rem .75rem;
transition:
background-color 250ms ease-out,
color 250ms ease-out;
}
.menu button:hover {
background-color: var(--c-light-gray);
}
.menu button.is-current {
background-color: var(--c-text);
color: var(--c-light-gray);
}
main {
margin: 2.25rem 0;
padding: 0 1rem;
}
.grid div {
border-radius: 3px;
box-shadow: 0 1px 3px var(--c-shadow);
margin-bottom: 1rem;
padding: 1rem;
}
.grid div span {
display: block;
font-size: calc(1vw + 1.5rem);
font-weight: 900;
padding: 1rem 1.5rem;
}
#module_1,
#module_1 span {
background-color: var(--c-red);
min-height: 200px;
}
#module_2,
#module_2 span {
background-color: var(--c-green);
min-height: 600px;
}
#module_3,
#module_3 span {
background-color: var(--c-blue);
min-height: 350px;
}
const layoutButtons = document.querySelectorAll('.js-layout-button');
const mainGrid = document.querySelector('.js-grid');
function changeLayout(e) {
e.preventDefault();
layoutButtons.forEach(button => {
button.classList.remove('is-current');
});
let layoutChoice = this.getAttribute('data-layout-toggle');
mainGrid.setAttribute('data-layout', layoutChoice);
this.classList.add('is-current');
}
layoutButtons.forEach(button => button.addEventListener('click', changeLayout));
Also see: Tab Triggers