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.
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
-
let boxes = [
{
"headline": "1",
"content": "π"
},
{
"headline": "2",
"content": "π"
},
{
"headline": "3",
"content": "π"
},
];
.headline
h1 Flex-Gap SASS Mixin
p Why is there no grid-gap property in flexbox!? Let's just go for it and create a flex-gap property, by using SASS mixin functionality! <a style="text-decoration:underline" href="http://bit.ly/2kMFuY8" target="_blank">(for more details read the related Article)</a>.
p // NOTE: in the meantime there is a gap property in flex-box! ^^
.stage.column
.container--grid.row
each box in boxes
.box
p= box.headline
p.emoj= box.content
.container--flex.row
each box in boxes
.box
p= box.headline
p.emoj= box.content
.switch-container
p flex-row
.switch
p flex-column
.article
a( href='http://bit.ly/2kMFuY8' target="_blank" ) π Read related Article
a( href='http://bit.ly/2JPuBjx' target="_blank" class='reference' ) π Ali Soueidan
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
$gap: 20px
//
// Here are the two mixins related to the article
//
=flexGap( $gap, $direction: row, $element: div )
> #{$element}
@if $direction == row
margin: 0 $gap/2
&:first-child
margin-left: 0
&:last-child
margin-right: 0
@if $direction == column
margin: $gap/2 0
&:first-child
margin-top: 0
&:last-child
margin-bottom: 0
//
// Here you can see how to use the mixins
//
body
display: flex
flex-direction: column
justify-content: space-around
align-items: center
+flexGap( $gap, column )
.stage
&.column
display: flex
flex-direction: column
+flexGap( $gap*2, column )
&.row
display: flex
+flexGap( $gap*2 )
.container--grid
&.row
display: grid
grid-gap: $gap*2
grid-template-columns: repeat(3, 1fr)
&.column
display: grid
grid-gap: $gap*2
.container--flex
&.row
display: flex
+flexGap($gap*2, row, "div")
&.column
display: flex
flex-direction: column
+flexGap($gap*2, column)
.container--grid, .container--flex
transition: .4s ease
.box
// transition: .4s ease
//
// Some editional styling
//
*
margin: 0px
padding: 0px
box-sizing: border-box
border: 0px
outline: 0
background-repeat: no-repeat
appearance: none
border-radius: 0
vertical-align: middle
font-weight: inherit
font-style: inherit
font-family: inherit
text-decoration: none
list-style: none
user-select: text
line-height: 1.333em
body
height: 100vh
.container--grid
&:before
content: "I am a grid container"
.container--flex
&.row
&:before
content: "I am a flex container"
&:after
content: ""flex
&.column
&:before
content: ""
&:after
content: "I am a flex container"
.container--superFlex
&:before
content: "I am a super-flex container"
.container--flex, .container--grid, .container--superFlex
position: relative
&:before
position: absolute
width: 200px
top: 50%
left: 0
transform: translate(calc(-100% - 40px), -50%)
text-align: right
font-family: 'roboto'
font-weight: 300
&:after
position: absolute
width: 200px
top: 50%
right: 0
transform: translate(calc(100% + 40px), -50%)
text-align: left
font-family: 'roboto'
font-weight: 300
.box
position: relative
padding: $gap
height: 120px
width: 120px
box-shadow: 0 0 20px hsla(0, 0, 0, .25)
background: hsla(0, 100, 100, .75)
border: 1px solid #ddd
border-radius: 5px
&:hover
cursor: pointer
background: hsla(249, 90, 77, 1)
.box
box-shadow: 0 0 0 hsla(0, 0, 0, 0)
border-radius: 0
.headline
width: 600px
h1, p, a
font-family: 'roboto'
h1
font-weight: 900
margin-bottom: $gap/2
color: #000
p
font-weight: 300
color: #000
&.emoj
position: absolute
bottom: 50%
right: 50%
transform: translate(50%,50%)
font-size: 50px
filter: grayScale(100%)
a
color: #000
.switch-container
display: flex
justify-content: flex-start
align-items: center
+flexGap( $gap*2 )
p
margin: 0
.switch
display: flex
width: 60px
background: hsla(0, 0, 0, .25)
border: 3px solid hsla(0, 0, 0, .5)
border-radius: $gap*4
cursor: pointer
transition: .4s ease
&:before
content: ""
display: flex
justify-content: center
align-items: center
width: 30px
height: 30px
color: hsla(0, 100, 100, 1)
background: hsla(0, 0, 0, .75)
border-radius: 50%
font-size: 15px
transition: .2s ease
&.on
&:before
transform: translateX( 24px ) rotate(360deg)
.reference
position: absolute
right: 24px
bottom: 24px
color: #000
text-decoration: none
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
// Setup swicth functions
const Switch = document.querySelector(".switch");
const FlexContainer = document.querySelector(".container--flex");
const GridContainer = document.querySelector(".container--grid");
const Stage = document.querySelector(".stage");
Switch.addEventListener("click", function() {
if ( this.classList.contains("on") ){
this.classList.remove("on");
FlexContainer.classList.remove("column");
FlexContainer.classList.add("row");
GridContainer.classList.remove("column");
GridContainer.classList.add("row");
Stage.classList.remove("row");
Stage.classList.add("column");
} else {
this.classList.add("on");
FlexContainer.classList.remove("row");
FlexContainer.classList.add("column");
GridContainer.classList.remove("row");
GridContainer.classList.add("column");
Stage.classList.remove("column");
Stage.classList.add("row");
}
});
Also see: Tab Triggers