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.
<!--
Feel free to use!
Follow me on Twitter: https://twitter.com/skarjan42
Or on GitHub: https://github.com/skarjan
-->
<html>
<head>
<title>Codepen
</title>
<link rel="stylesheet" href="css/codepen.css">
</head>
<body>
<nav class="nav">
<div>
<a href="#">
<h1 class="fancy clr-blue">website.com</h1>
</a>
</div>
<div class="link-lang-container">
<div class="hide" id="linkContainer">
<div class="active-link anchor">
<a href="#">Home</a>
<div class="active-border border">
Home
</div>
</div>
<div class="hov-link anchor">
<a href="#">CV</a>
<div class="hov-border border">
CV
</div>
</div>
<div class="hov-link anchor">
<a href="#">GitHub</a>
<div class="hov-border border">
GitHub
</div>
</div>
</div>
<div class="sm-menu-container">
<div class="active-lang nl lang-anchor">
<a href="#">NL</a>
<div class="active-lang-border lang-border">
<!-- hack to get language highlighting without border -->
</div>
</div>
<span>|</span>
<div class="lang-link eng lang-anchor">
<a href="#">ENG</a>
<div class="lang-border lang-border">
<!-- hack to get language highlighting without border -->
</div>
</div>
<div class="nav-menu-sm">
<button class="menu-hb" id="menu-hb" type="button"><svg height="25" viewbox="0 0 100 45" width="25">
<rect height="10" width="100" y="0">
</rect>
<rect height="10" width="100" y="30">
</rect>
<rect height="10" width="100" y="60">
</rect>
</svg></button>
</div>
</div>
</div>
</nav>
<div class="flex-items-centered">
<div>
<h1 class="fancy display-lg flex-items-centered vh-90">Responsive Navigation/Menu</h1>
</div>
</div>
</body>
</html>
/* fonts */
@import url("https://fonts.googleapis.com/css2?family=Orelega+One&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Happy+Monkey&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Bowlby+One+SC&family=Bungee&display=swap");
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700);
/* colors */
/* primary: #5a189a */
/* reset */
* {
margin: 0;
padding: 0;
font-size: inherit;
color: inherit;
box-sizing: inherit;
backface-visibility: hidden;
-webkit-font-smoothing: antialiased;
}
*:focus {
outline: none;
}
html,
body {
height: 100%;
/* different from scss source */
overflow: auto;
/* different from scss source */
}
html {
font-size: 16px;
box-sizing: border-box;
}
body {
background-color: #ecf0f1;
min-width: 300px;
font-family: "Open Sans", sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6 {
display: block;
font-weight: 400;
}
li,
span,
p,
a,
h1,
h2,
h3,
h4,
h5,
h6 {
line-height: 1;
}
p {
display: block;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
img {
display: block;
max-width: 100%;
height: auto;
border: 0;
}
button {
background-color: transparent;
border: 0;
cursor: pointer;
}
.show {
display: inline-block;
opacity: 1;
}
/* Element styles */
html {
font-size: 15px;
}
body {
background-color: #ffffff;
line-height: 1.4em;
}
a:hover {
text-decoration: none;
}
h1 {
font-size: 1.6rem;
font-weight: 900;
}
h2 {
font-size: 1.5rem;
font-weight: 800;
}
h3 {
font-size: 1.4rem;
font-weight: 800;
}
h4 {
font-size: 1.3rem;
font-weight: 700;
}
h5 {
font-size: 1.2rem;
font-weight: 600;
}
h6 {
font-size: 1.1rem;
font-weight: 500;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 0;
line-height: 1.2;
margin-bottom: 0.5rem;
}
p {
margin-top: 0;
font-size: 1rem;
margin-bottom: 1rem;
line-height: 1.1;
}
small {
font-size: 12px;
}
/* Flex classes */
.flex-items-centered {
display: flex;
align-items: center;
align-content: flex-start;
justify-content: center;
}
.flex-horizontal {
display: flex;
}
/* utility classes */
.clr-blue {
color: #5a189a;
}
.clr-dark-red {
color: #7c0000;
}
.sm-text {
font-size: 12px;
}
.display-lg {
font-size: 3rem;
}
.vh-90 {
height: 75vh;
}
/* custom styles */
/* baseline */
.shadow {
box-shadow: 0px 2px 18px 0px rgb(0 0 0 / 30%);
}
.text-content {
color: black;
}
.image-content {
min-width: 65px;
}
.skills {
font-size: 12px;
}
.quote-container {
font-size: 14px;
float: right;
}
.img-container {
padding: 16px;
margin: 8px;
max-width: 682px;
}
.img-container i {
line-height: 1.7rem;
}
.nav {
display: flex;
justify-content: space-between;
align-items: center;
min-width: 320px;
max-width: 1080px;
margin: 0 auto;
padding: 34px;
border-bottom: 1px solid #dcdcdc;
}
.hov-link,
.lang-link {
padding: 8px 12px;
display: inline-block;
position: relative;
}
.eng {
padding: 8px 12px 8px 0 !important;
}
.nl {
padding: 8px 0 8px 12px !important;
}
.hov-border,
.lang-border {
position: absolute;
top: 34px;
border-top: solid 3px rgb(90, 24, 154, 0%);
color: rgb(0, 0, 0, 0%);
transition-property: border-top, top;
transition-duration: 0.4s, 0.5s;
}
.hov-link:hover > .hov-border,
.lang-link:hover > .lang-border {
border-top: solid 3px rgb(90, 24, 154, 100%);
top: 30px;
}
.active-link,
.active-lang {
position: relative;
padding: 8px 12px;
display: inline-block;
position: relative;
color: #5a189a;
}
.active-border,
.active-lang-border {
position: absolute;
top: 30px;
color: rgb(0, 0, 0, 0%);
border-top: 3px solid #5a189a;
}
/* this hides the copy of text which is used to determine the border length */
.border {
user-select: none;
}
.flex-container {
padding: 36px 8px;
margin: 0 auto;
max-width: 1024px;
display: flex;
justify-content: space-between;
align-items: center;
}
.fancy {
font-family: "Bungee", cursive;
font-weight: 500;
margin: 0;
}
.sm-menu-container {
font-size: 14px;
}
/* end of baseline */
/* responsiveness */
/* big phones */
@media only screen and (min-width: 444px) and (max-width: 768px) {
}
/* big and small phones */
@media only screen and (max-width: 768px) {
.hide {
display: none;
opacity: 0;
}
nav {
position: relative;
}
.responsive-links {
box-shadow: 0px 8px 18px 0px rgb(0 0 0 / 30%);
max-width: 748px;
width: 100%;
top: 75px;
left: 0px;
background-color: #fff;
position: absolute;
padding-bottom: 16px;
transition: top, 0.2s;
z-index: 1;
padding: 8px 0;
transition: top, 0.5s;
}
.display-lg {
font-size: 1.8rem;
}
.responsive-links > div {
display: block;
}
.sm-menu-container {
display: flex;
align-items: center;
font-size: 14px;
}
}
/* tablets */
@media only screen and (min-width: 768px) and (max-width: 1080px) {
.hide {
display: none;
}
.sm-menu-container {
display: flex;
align-items: center;
font-size: 14px;
}
.display-lg {
font-size: 2.5rem;
}
.responsive-links {
box-shadow: 0px 8px 18px 0px rgb(0 0 0 / 30%);
max-width: 1060px;
min-width: 768px;
width: 100%;
top: 75px;
left: 0;
background-color: #fff;
position: absolute;
padding: 8px 0;
transition: top, 0.5s, opacity, 0.4s;
opacity: 0;
z-index: 1;
}
.responsive-links > div {
display: block;
}
}
@media only screen and (min-width: 1080px) {
.link-lang-container {
display: flex;
align-items: baseline;
}
.nav-menu-sm {
display: none;
}
}
"use strict";
function isLinkExternal(anchor) {
return anchor.children[0].hasAttribute("target");
}
function addMenuEventListeners() {
// show/hide when clicking the hamburger icon
document.getElementById("menu-hb").addEventListener("click", toggleMenu);
// hide when clicking (almost) anywhere on the page
document
.getElementsByTagName("body")[0]
.addEventListener("click", toggleMenu);
// event listeners to display active/inactive links
addClickListeners(
"anchor",
"border",
"active-link",
"active-border",
"hov-link",
"hov-border"
);
addClickListeners(
"lang-anchor",
"lang-border",
"active-lang",
"active-lang-border",
"lang-link",
"lang-border"
);
}
function addClickListeners(
link,
border,
activeAnchor,
activeBorder,
anchor,
regularBorder
) {
let links = document.getElementsByClassName(link);
let borders = document.getElementsByClassName(border);
for (let i = 0; i < links.length; i++) {
links[i].addEventListener("click", function () {
let self = this;
if (!isLinkExternal(self)) {
deactivateLink(activeAnchor, activeBorder, anchor, regularBorder);
activateLink(
links,
borders,
i,
activeAnchor,
activeBorder,
anchor,
regularBorder
);
}
});
}
}
function deactivateLink(activeAnchor, activeBorder, anchor, border) {
// needs the active language lin
let elLink = document.getElementsByClassName(activeAnchor);
let elBorder = document.getElementsByClassName(activeBorder);
// needs the inactive language link
elLink[0].classList.add(anchor);
elLink[0].classList.remove(activeAnchor);
elBorder[0].classList.add(border);
elBorder[0].classList.remove(activeBorder);
}
function activateLink(
links,
borders,
i,
activeAnchor,
activeBorder,
anchor,
border
) {
links[i].classList.add(activeAnchor);
links[i].classList.remove(anchor);
borders[i].classList.add(activeBorder);
borders[i].classList.remove(border);
}
function toggleMenu() {
let self = this;
// show/hide on hb menu icon click
let linkContainer = document.getElementById("linkContainer");
if (
linkContainer.classList[0] !== "responsive-links" &&
self.classList[0] == "menu-hb"
) {
// show
linkContainer.classList.add("responsive-links");
linkContainer.classList.add("show");
linkContainer.classList.remove("hide");
// animate
// begin state
document.getElementsByClassName("responsive-links")[0].style.opacity = "0";
// end state
setTimeout(function () {
document.getElementsByClassName("responsive-links")[0].style.top =
"106px";
document.getElementsByClassName("responsive-links")[0].style.opacity =
"100";
}, 1);
} else if (
linkContainer.classList[0] == "responsive-links" &&
self.classList[0] === "menu-hb"
) {
// animate
document.getElementsByClassName("responsive-links")[0].style.top = "75px";
document.getElementsByClassName("responsive-links")[0].style.opacity = "0";
// hide
setTimeout(function () {
linkContainer.classList.remove("responsive-links");
linkContainer.classList.remove("show");
linkContainer.classList.add("hide");
}, 400);
}
// hide menu if user clicks on the body
if (
linkContainer.classList[0] == "responsive-links" &&
self.classList[0] == "content"
) {
// animate
document.getElementsByClassName("responsive-links")[0].style.opacity = "0";
document.getElementsByClassName("responsive-links")[0].style.top = "75px";
// document.getElementsByClassName("responsive-links")[0].style.opacity = "0";
// hide
setTimeout(function () {
linkContainer.classList.remove("responsive-links");
linkContainer.classList.remove("show");
linkContainer.classList.add("hide");
}, 400);
}
}
// Work around for opacity issue
function is1080Wide() {
var mQ = window.matchMedia("(min-width: 1080px)");
mQ.addEventListener("change", setOpacityOnLinks);
}
function setOpacityOnLinks(mediaQuery) {
if (mediaQuery.matches) {
document.getElementById("linkContainer").style.opacity = 1;
}
}
addMenuEventListeners();
is1080Wide();
Also see: Tab Triggers