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 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.
<div class="dropdown-menu ddm1">
<input type="checkbox" name="toggle" id="toggle">
<label for="toggle">Menu</label>
<ul>
<li><a href="#" title="Do something">Do something</a></li>
<li><a href="#" title="Do something else">Do something else</a></li>
<li><a href="#" title="Options">Options</a></li>
</ul>
</div>
/* Comment réaliser un menu déroulant uniquement en CSS */
* {
/* On retire toutes les marges pour faciliter la mise en page */
padding:0;
margin:0;
}
.dropdown-menu {
/* On positionne le conteneur au centre et on lui assigne un placement
relatif pour pouvoir placer ses enfants en absolu */
position:relative;
width:200px;
margin:20px auto;
font-family:'Helvetica', Arial, sans-serif; /* On change la police */
}
.dropdown-menu label {
/* On définit une couleur de fond, de trait et de contour pour le bouton */
background:#1e83e5;
color:#fff; /* Fallback pour les navigateurs ne comprenant pas le rgba */
color:rgba(0,0,0,0.6);
border:1px solid #fff; /* Fallback pour les navigateurs ne comprenant pas le rgba */
border:1px solid rgba(0,0,0,0.4);
/* On termine de déclarer les styles typographiques */
font-weight:bold;
text-shadow:0 1px 1px rgba(255,255,255,0.2);
/* On position l'élément et on spécifie ses marges */
display:block;
float:left;
position:relative;
padding:5px 35px 5px 25px;
/* On ajoute quelques styles user-friendly */
cursor:pointer; /* Indique que le bouton est cliquable */
border-radius:0.3em; /* Valeur passe-partout pour les bords arrondis */
box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), /* Reflet en haut du bouton */
inset 0 10px 30px rgba(255,255,255,0.3), /* Evite un applat de couleur */
0 0 0 3px rgba(100,100,100,0.1), /* Renfoncement du bouton dans la matière */
2px 2px 3px rgba(0,0,0,0.1); /* Ombre portée */
transition:all 0.3s ease-out;
}
/* On met en place le triangle indiquant qu'il s'agit d'un menu déroulant
par le biais d'un pseudo-élément afin de ne pas utiliser d'image
Dans le cas d'un vieux navigateur, l'icone n'apparaitra pas : tant pis */
.dropdown-menu label:after {
content: ""; /* Pas de contenu : élément visuel */
/* On place l'élément */
position: absolute;
top: 50%;
right: 10px;
/* Ci-dessous la méthode pour avoir un triangle en CSS */
width: 0;
height: 0;
border-left: 6px solid transparent;
border-top: 6px solid rgba(0,0,0,0.6);
border-right: 6px solid transparent;
margin-left: -3px;
margin-top: -3px;
}
/* On met en place un état survolé au menu */
.dropdown-menu label:hover {
background:#4caffa;
}
/* Afin de gérer un élément "onclick" qui perdure en CSS,
on utilise une méthode impliquant une checkbox et le pseudo-selector :checked */
.dropdown-menu input[type="checkbox"] {
/* On position la checkbox hors écran, le label servira de déclencheur */
position:absolute;
clip:rect(0,0,0,0); /* Permet de réduire sa zone d'affichage à 0 */
top:9999px;
}
/* On met en place la liste du menu */
.dropdown-menu ul {
/* On place le menu */
position:absolute;
top:42px;
/* On paramètre ses styles */
list-style-type:none;
padding:5px 0;
font-size:13px;
border:1px solid #ddd;
border-radius:0.3em;
box-shadow:0 5px 10px rgba(0,0,0,0.2);
/* Et on le cache pour finir */
display:none;
}
/* On met en place une petite flèche au menu pour indique qu'il descend du bouton */
.dropdown-menu ul:after,
.dropdown-menu ul:before {
content:"";
height:0;
width:0;
position:absolute;
bottom:100%;
border:solid transparent;
}
.dropdown-menu ul:after {
border-bottom-color:#fff;
border-width:6px;
left:15%;
margin-left:-6px;
}
.dropdown-menu ul:before {
border-bottom-color:#ddd;
border-width:7px;
left:15%;
margin-left:-7px;
}
/* On style les liens du menu */
.dropdown-menu a {
text-decoration:none;
color:#333;
display:block;
padding:5px 15px;
}
/* On paramètre le dernier élément du menu afin qu'il ait une bordure supérieure
pour le différencier des autres sans pour autant gérer une classe supplémentaire
à l'aide du pseudo-selecteur :last-of-type */
.dropdown-menu li:last-of-type {
margin-top:4px;
border-top:1px solid silver;
border-top:1px solid rgba(0,0,0,0.2);
}
/* On paramètre un survol aux éléments du menu */
.dropdown-menu a:hover {
background:#0088CC;
color:#fff;
}
/* On déclare que si la checkbox est cochée, la liste est affichée */
.dropdown-menu input[type="checkbox"]:checked ~ ul {
display:block;
}
/* On met en place quelques styles au bouton si le menu est affiché */
.dropdown-menu input[type="checkbox"]:checked ~ label {
left:1px; /* Décale le bouton de 1px vers la droite */
top:1px; /* Décale le bouton de 1px vers le bas */
box-shadow: inset 0 1px 0 rgba(255,255,255,0.4),
inset 0 10px 30px rgba(255,255,255,0.3),
0 0 0 3px rgba(100,100,100,0.05);
background:#4caffa;
}
Also see: Tab Triggers