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.
section.hero.is-light.is-medium
div.hero-body
div.container
h1.title Testing Masonry - Cascading grid layout library
h2.subtitle
a(href="https://www.instagram.com/dan10gc/?hl=en") Images by Daniel Gonzalez
div.hero-foot
nav.tabs.is-boxed.is-fullwidth
div.container
ul#buttonGroup
li.is-active
a#all All Images
li
a#newYork New York City
li
a#flowers Flowers
li
a#others Other
div.grid#container
div.grid-sizer
div.grid-item.flowers
img(src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/sunFlowerNJ.jpg' alt='')
div.grid-item.flowers
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/flowers.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/AmericanStandardBuilding.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/nycGalaxy.jpg")
div.grid-item.flowers
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/butterflyOnFlower.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/nycBuilding2.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/falafelPost.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/littleRedLightHouse.jpg")
div.grid-item.flowers
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/gwFlowerB%26W.jpg")
div.grid-item.others
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/highwayExposure2.jpg")
div.grid-item.flowers
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/flowerWithButterfly.jpg")
div.grid-item.flowers
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/flowerWithBee.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/oilTankerHudson.jpg")
div.grid-item.flowers
img(src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/flowersCloseUp2.jpg' alt='')
div.grid-item.others
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/redMillB%26W.jpg")
div.grid-item.newYork
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/commuteToWork.jpg")
div.grid-item.others
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/miamiNeonSign.jpg")
div.grid-item.flowers
img(src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/redFlowerBleachBypass.jpg' alt='')
div.grid-item.newYork
img(src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1362379/wrGraceBuilding.jpg')
$black: #333333;
* {
box-sizing: border-box;
}
.grid{
background: $black;
}
.grid:after {
content: '';
display: block;
clear: both;
}
.grid-sizer,
.grid-item {
width: 33.33%;
}
.grid-item{
float: left;
&:hover{
cursor:pointer;
}
}
.grid-item img{
display: block;
max-width: 100%;
border: 10px solid white;
@media screen and (max-width: 414px){
border: 5px solid white;
}
}
.grid-item.grid-item__expanded {
width: 66.66%;
z-index: 2;
}
var grid = document.querySelector('.grid');
var msnry;
// element selectors
var imgAll = document.querySelectorAll('.grid-item');
var imgNy = document.querySelectorAll('.newYork');
var imgFlowers = document.querySelectorAll('.flowers');
var imgOthers = document.querySelectorAll('.others');
// buttons
const tabsUl = document.getElementById('buttonGroup');
const lis = tabsUl.children;
const gridItems = grid.children;
imagesLoaded(grid, function(){
msnry = new Masonry( grid, {
//options
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
percentPosition: true
});
});
//element & class name
function toggleClass(parentElem, childElems, className){
for(let i = 0; i <childElems.length; i++){
if(childElems[i]==parentElem){
childElems[i].classList.add(className);
}
else{
childElems[i].classList.remove(className);
}
}
}
function showImages(showImg, hideImg1, hideImg2){
for(let i = 0; i < showImg.length; i++){
showImg[i].style.display = "block";
}
for(let i = 0; i < hideImg1.length; i++){
hideImg1[i].style.display = "none";
}
for(let i = 0; i< hideImg2.length; i++){
hideImg2[i].style.display = "none";
}
}
tabsUl.addEventListener('click', (event) =>{
let tabLi = event.target.parentNode;
toggleClass(tabLi, lis, 'is-active');
//show all images
if(event.target.id == "all"){
for(let i = 0; i< imgAll.length; i++){
imgAll[i].style.display = "block";
}
}
//show ny images
if(event.target.id == "newYork"){
showImages(imgNy, imgFlowers, imgOthers);
}
// show flowers
if(event.target.id == "flowers"){
showImages(imgFlowers, imgNy, imgOthers);
}
// show other images
if(event.target.id == "others"){
showImages(imgOthers, imgFlowers, imgNy);
}
msnry.layout();
});
grid.addEventListener('click',function(event){
let imgContainer = event.target.parentNode;
toggleClass(imgContainer, gridItems, 'grid-item__expanded');
msnry.layout();
});
Also see: Tab Triggers