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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
#app
$movieContentBg: #ddd
=scaleUp
opacity: 1
transform: scale(1)
=scaleDown($delay: 0)
transform: scale(0)
opacity: 0
transition: transform .24s ease-in $delay, opacity .3s linear
*,*::before,*::after
margin: 0
padding: 0
box-sizing: border-box
a
text-decoration: none
.movies__container
display: flex
flex-wrap: wrap
margin: 0 auto
width: 95%
padding-top: 30px
justify-content: space-around
color: #ddd
.movie
margin: 5px
padding: 20px 5px 10px
display: flex
flex-direction: column
justify-content: space-between
background-blend-mode: color
max-width: 270px
height: 400.1px
box-shadow: 10px 10px 10px #111
transition: background-color .25s linear
text-align: center
font-family: 'Roboto', sans-serif
background-size: cover
&:hover
background-color: rgba(0,0,0,.8)
.movie__title,
.movie__description,
.movie__infos div,
.movie__rating,
.movie__imdb-button
+scaleUp
.movie__title
+scaleDown
text-transform: uppercase
.movie__description
max-height: 200px
+scaleDown(0.05s)
.movie__infos
display: grid
grid-gap: 10px 0
grid-template-columns: repeat(2,1fr)
align-items: center
.info__head
display: block
margin-bottom: 4px
font-weight: bold
font-size: 1.1em
.movie__duration
+scaleDown(0.15s)
.movie__director
+scaleDown(0.20s)
.movie__year
+scaleDown(0.25s)
.movie__cast
+scaleDown(0.30s)
font-size: .9em
.movie__imdb
display: flex
justify-content: space-between
align-items: center
justify-self: flex-end
padding: 0 10px
.movie__rating
+scaleDown(0.35s)
.fa-star
width: 9px
font-size: 1.2em
display: inline-block
overflow: hidden
&.checked
color: yellow
.movie__imdb-button
width: 60px
height: 30px
border-radius: 5px
background-color: #EBBA33
display: flex
justify-content: center
align-items: center
color: #000
font-family: 'Oswald', sans-serif
font-size: 1.1em
font-weight: bold
cursor: pointer
+scaleDown(0.40s)
const Rating = ({rating}) => {
let stars = [];
for (let i = 1; i < 11; i++) {
let klass = "fa fa-star";
if (rating >= i && rating !== null) {
klass = "fa fa-star checked";
}
stars.push(
<i
style={{ direction: (i%2===0) ? "rtl" : "ltr"}}
className={klass}
/>
);
}
return (
<div className="movie__rating">
{stars}
</div>
);
}
const MovieInfo = ({name,value}) => (
<div className={`movie__${name}`}>
<span className='info__head'>
{name.replace(/\b\w/g, l => l.toUpperCase())}
</span>
{value}
</div>
)
const Movie = ({infos}) => {
const cast = infos.cast.map(actor => (
<p key={actor}>{actor}</p>
))
return(
<div className='movie' style={{backgroundImage: `url(${infos.poster})`}}>
<h2 className='movie__title'>{infos.title}</h2>
<span className='movie__description'>{infos.description}</span>
<div className='movie__infos'>
<MovieInfo name='duration' value={infos.duration} />
<MovieInfo name='director' value={infos.director} />
<MovieInfo name='year' value={infos.year} />
<MovieInfo name='cast' value={cast} />
</div>
<div className='movie__imdb'>
<Rating rating={Math.round(infos.rating)}/>
<a href={infos.imdbLink} className='movie__imdb-button' target='blank'> IMDb </a>
</div>
</div>
)
}
class App extends React.Component {
constructor(props){
super(props);
}
render() {
const moviesList = this.props.infos.map((movie,i)=> (
<Movie key={i} infos={movie}/>
))
return (
<div className='movies__container'>
{moviesList}
</div>
)
}
}
const infos = [
{
title: 'Thor',
description: 'The powerful, but arrogant god Thor, is cast out of Asgard to live amongst humans in Midgard (Earth), where he soon becomes one of their finest defenders.',
duration: '124',
year: '2011',
director: 'Kenneth Branagh',
cast: ['Chris Hemsworth','Anthony Hopkins','Natalie Portman'],
rating: 8.7,
imdbLink: 'https://www.imdb.com/title/tt0800369/',
poster: 'http://media.comicbook.com/2017/10/thor-movie-poster-marvel-cinematic-universe-1038890.jpg'
},
{
title: 'The Shawshank Redemption',
description: 'Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.',
duration: '142',
year: '1994',
director: 'Frank Darabont',
cast: ['Tim Robbins', 'Morgan Freeman', 'Bob Gunton'],
rating: 9.3,
imdbLink: 'https://www.imdb.com/title/tt0111161/',
poster: "https://ae01.alicdn.com/kf/HTB1xKI9PFXXXXXAXVXXq6xXFXXXG/Dropship-The-Shawshank-Redemption-Nostalgia-classic-movie-kraft-paper-bar-poster-Retro-Poster-decorative-painting.jpg"
},
{
title: 'The Silence of the Lambs',
description: 'A young F.B.I. cadet must receive the help of an incarcerated and manipulative cannibal killer to help catch another serial killer, a madman who skins his victims.',
duration: '118',
year: '1991',
director: 'Jonathan Demme',
cast: ['Jodie Foster', 'Anthony Hopkins', 'Lawrence A. Bonney'],
rating: 8.6,
imdbLink: 'https://www.imdb.com/title/tt0102926/',
poster: "https://m.media-amazon.com/images/M/MV5BNjNhZTk0ZmEtNjJhMi00YzFlLWE1MmEtYzM1M2ZmMGMwMTU4XkEyXkFqcGdeQXVyNjU0OTQ0OTY@._V1_SY1000_CR0,0,677,1000_AL_.jpg"
},
{
title: 'Spirited Away',
description: "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.",
duration: '125',
year: '2001',
director: 'Hayao Miyazaki',
cast: ['Daveigh Chase', 'Suzanne Pleshette', 'Miyu Irino'],
rating: 8.6,
imdbLink: 'https://www.imdb.com/title/tt0245429/',
poster: "https://m.media-amazon.com/images/M/MV5BOGJjNzZmMmUtMjljNC00ZjU5LWJiODQtZmEzZTU0MjBlNzgxL2ltYWdlXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SY1000_CR0,0,675,1000_AL_.jpg"
},
{
title: 'Starship Troopers',
description: "Humans in a fascistic, militaristic future do battle with giant alien bugs in a fight for survival.",
duration: '129',
year: '1997',
director: 'Paul Verhoeven',
cast: ['Casper Van Dien', 'Denise Richards', 'Dina Meyer'],
rating: 7.2,
imdbLink: 'https://www.imdb.com/title/tttt0120201/',
poster: "https://m.media-amazon.com/images/M/MV5BNThlOTFhOGEtZjE2NC00MzMzLThkYWItZjlkNWNlMDAzMGZkXkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SY1000_CR0,0,732,1000_AL_.jpg"
},
]
ReactDOM.render(<App infos={infos}/>, document.getElementById('app'));
Also see: Tab Triggers