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.
<!---
Restaurant Menu
-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.1/css/all.css">
<link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&family=Rubik:wght@300;700&display=swap" rel="stylesheet">
<div class="container">
<div class="header">
<div class="title">Menu</div>
</div>
<div class="indicators">
<div id="i1">
<div class="navi-indicator" id="ni1"></div>
</div>
<div id="i2">
<div class="navi-indicator" id="ni2"></div>
</div>
<div id="i3">
<div class="navi-indicator" id="ni3"></div>
</div>
<div id="i4">
<div class="navi-indicator" id="ni4"></div>
</div>
</div>
<div class="navi">
<div class="navi-item1">
<button class="nav-button" id="startersbutton">
<div class="navi-icon"><i class="fas fa-seedling"></i></div>
<div class="navi-text">Starters</div>
</button>
</div>
<div class="navi-item2">
<button class="nav-button" id="mainsbutton">
<div class="navi-icon"><i class="fas fa-pizza-slice"></i></div>
<div class="navi-text">Mains</div>
</button>
</div>
<div class="navi-item3">
<button class="nav-button" id="dessertsbutton">
<div class="navi-icon"><i class="fas fa-ice-cream"></i></div>
<div class="navi-text">Desserts</div>
</button>
</div>
<div class="navi-item4">
<button class="nav-button" id="drinksbutton">
<div class="navi-icon"><i class="fas fa-wine-glass-alt"></i></div>
<div class="navi-text">Drinks</div>
</button>
</div>
</div>
<div class="menu">
<div class="menu-separator">Separator</div>
<div class="menu-item">
<div class="menu-item-name">Food</div>
<div class="menu-item-description">Food yada yada</div>
<div class="menu-item-price">17.50</div>
</div>
<div class="menu-separator">Separator</div>
<div class="drink-item">
<div class="drink-item-name">Drink</div>
<div class="drink-item-description">3.3dl</div>
<div class="drink-item-price">4.50</div>
</div>
</div>
</div>
/*<!---
Restaurant Menu
-->*/
:root {
--bg: #fffdf2;
--tst: #d1e8ff;
--radius: 10px;
--icolor1: #c4e85a;
--icolor2: #ffb370;
--icolor3: #d65ae8;
--icolor4: #63c8ff;
}
body {
font-family: "Rubik", sans-serif;
color: #111;
}
.container {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 100vh;
display: grid;
grid-template-columns: 5% auto 5%;
grid-template-rows: 140px 80px auto 100px 30px;
background: var(--bg);
/* mobile viewport bug fix */
height: -webkit-fill-available;
}
.header {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
font-family: "Dancing Script", cursive;
}
.title {
width: 100%;
height: 100%;
line-height: 150px;
font-size: 70px;
text-align: center;
}
.indicators {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 5;
grid-row-end: 5;
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-template-rows: 10px;
}
#i1,
#i2,
#i3,
#i4 {
grid-column-start: 1;
grid-column-end: 1;
display: flex;
align-items: center;
justify-content: center;
}
#i2 {
grid-column-start: 2;
grid-column-end: 2;
}
#i3 {
grid-column-start: 3;
grid-column-end: 3;
}
#i4 {
grid-column-start: 4;
grid-column-end: 4;
}
.navi-indicator {
height: 4px;
width: 60px;
border-radius: 20px;
transition: width 0.2s;
}
#ni1{
background: var(--icolor1);
}
#ni2{
background: var(--icolor2);
}
#ni3{
background: var(--icolor3);
}
#ni4{
background: var(--icolor4);
}
.navi {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 4;
grid-row-end: 4;
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-template-rows: 100px;
}
.navi-item1,
.navi-item2,
.navi-item3,
.navi-item4 {
grid-column-start: 1;
grid-column-end: 2;
display: flex;
align-items: center;
justify-content: center;
}
.navi-item2 {
grid-column-start: 2;
grid-column-end: 2;
}
.navi-item3 {
grid-column-start: 3;
grid-column-end: 3;
}
.navi-item4 {
grid-column-start: 4;
grid-column-end: 4;
}
.nav-button {
height: 70px;
width: 70px;
border-radius: 20px;
background: linear-gradient(145deg, #e6e4da, #ffffff);
box-shadow: 6px 6px 10px #cfcdc4, -6px -6px 10px #ffffff;
font-family: "Rubik", sans-serif;
font-weight: 700;
cursor: pointer;
}
#startersbutton .navi-icon {
color: var(--icolor1);
}
#mainsbutton .navi-icon {
color: var(--icolor2);
}
#dessertsbutton .navi-icon {
color: var(--icolor3);
}
#drinksbutton .navi-icon {
color: var(--icolor4);
}
.navi-icon {
height: 40px;
line-height: 50px;
font-size: 20px;
text-align: center;
}
.navi-text {
height: 30px;
line-height: 20px;
text-align: center;
font-size: 0.9em;
font-weight: 300;
}
.menu {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 2;
grid-row-end: 4;
overflow-y: auto;
}
.menu-item {
grid-column-start: 2;
grid-column-end: 2;
height: 110px;
margin: 15px;
display: grid;
grid-template-columns: auto 90px;
grid-template-rows: 40px 60px;
font-size: 0.9em;
border-radius: var(--radius);
padding-left: 30px;
padding-top: 10px;
background: linear-gradient(145deg, #ffffff, #e6e4da);
box-shadow: 6px 6px 10px #c7c5bd, -6px -6px 10px #ffffff;
}
.menu-item-name {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
font-weight: 700;
line-height: 50px;
}
.menu-item-description {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 2;
grid-row-end: 2;
}
.menu-item-price {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 3;
font-weight: 700;
line-height: 100px;
text-align: center;
}
.drink-item {
grid-column-start: 2;
grid-column-end: 2;
height: 50px;
margin: 15px;
display: grid;
grid-template-columns: auto 30px 90px;
grid-template-rows: 50px;
font-size: 0.9em;
border-radius: var(--radius);
padding-left: 30px;
padding-top: 10px;
background: linear-gradient(145deg, #ffffff, #e6e4da);
box-shadow: 6px 6px 10px #c7c5bd, -6px -6px 10px #ffffff;
}
.drink-item-name {
grid-column-start: 1;
grid-column-end: 2;
font-weight: 700;
line-height: 50px;
}
.drink-item-description {
grid-column-start: 2;
grid-column-end: 2;
line-height: 50px;
}
.drink-item-price {
grid-column-start: 3;
grid-column-end: 3;
font-weight: 700;
line-height: 50px;
text-align: center;
}
.menu-separator {
grid-column-start: 2;
grid-column-end: 2;
height: 50px;
margin: 15px;
margin-top: 35px;
font-size: 1.2em;
line-height: 50px;
font-weight: 700;
border-radius: var(--radius);
padding-left: 30px;
background: linear-gradient(145deg, #ffffff, #e6e4da);
box-shadow: 6px 6px 10px #c7c5bd, -6px -6px 10px #ffffff;
}
/*Desktop Stuff*/
@media only screen and (min-width: 800px) {
.container {
grid-template-rows: 150px 100px 20px auto 20px;
}
.indicators {
grid-row-start: 3;
grid-row-end: 4;
}
.navi-indicator {
height: 4px;
width: 100%;
margin: 15px;
}
.navi {
grid-row-start: 2;
grid-row-end: 3;
}
.navi-item1,
.navi-item2,
.navi-item3,
.navi-item4 {
display: flex;
}
.nav-button {
height: 70px;
width: 100%;
margin: 15px;
display: flex;
justify-content: center;
border-radius: var(--radius);
}
.navi-icon {
height: 100%;
line-height: 70px;
font-size: 25px;
text-align: center;
}
.navi-text {
line-height: 70px;
margin-left: 10px;
text-align: left;
font-size: 1.3em;
font-weight: 700;
}
.menu {
grid-row-start: 4;
grid-row-end: 4;
}
}
/*prevent defaults*/
button,
p {
display: inline-block;
border: none;
margin: 0;
text-decoration: none;
padding: 0;
background: none;
border-radius: 0;
-webkit-appearance: none;
-moz-appearance: none;
overflow: hidden;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
input {
padding: 0;
}
input:focus {
outline: none;
}
button:focus {
outline: none;
color: var(--maincolor);
}
textarea:focus {
outline: none;
}
select:focus {
color: #39a;
}
a,
a:link,
a:visited {
color: var(--maincolor);
}
//////////////////////
//Restaurant Menu
//////////////////////
const starters = JSON.parse(
"[" +
'{ "type":"separator", "description":"APPETIZERS" },' +
'{ "type":"food", "name":"CROSTINI", "description":"with diced tomatoes, onions, garlic and basil", "price":"12.00" },' +
'{ "type":"food", "name":"NACHOS", "description":"with 2 dips of your choice, gratinated with cheese and sliced chicken", "price":"10.50" },' +
'{ "type":"separator", "description":"SALADS" },' +
'{ "type":"food", "name":"CHICKEN CHILI SALAD", "description":"mixed salad, fried sliced chicken marinated with honey and chili", "price":"25.00" },' +
'{ "type":"food", "name":"FENNEL-APPLE SALAD", "description":"with rocket, feta, cranberries and pumpkin seeds", "price":"15.00" },' +
'{ "type":"food", "name":"CAESAR`S SALAD", "description":"Lettuce with fried baconstrips, croûtons, Grana Padano, egg and Caesar Dressing", "price":"16.00" } ]'
);
const mains = JSON.parse(
"[" +
'{ "type":"separator", "description":"PIZZA" },' +
'{ "type":"food", "name":"MARGHERITA", "description":"Tomato sauce, mozzarella, organic oregano", "price":"18.00" },' +
'{ "type":"food", "name":"PROSCIUTTO", "description":"Tomato sauce, mozzarella, ham, organic oregano", "price":"21.50" },' +
'{ "type":"food", "name":"SALAME", "description":"Tomato sauce, mozzarella, salami, organic oregano", "price":"21.00" },' +
'{ "type":"food", "name":"TONNO", "description":"Tomato sauce, mozzarella, tuna MSC, capers, organic oregano", "price":"19.50" },' +
'{ "type":"separator", "description":"MEAT & FISH" },' +
'{ "type":"food", "name":"SURF & TURF", "description":"Beef entrecĂ´te with herb butter, vegetables and fries", "price":"48.00" },' +
'{ "type":"food", "name":"RUMP STEAK", "description":"with café de paris herbs butter, fries and vegetables", "price":"35.00" },' +
'{ "type":"food", "name":"FISH & CHIPS", "description":"Cod in beer batter with french fries and mashed peas", "price":"25.00" },' +
'{ "type":"separator", "description":"PASTA" },' +
'{ "type":"food", "name":"LINGUINE", "description":"on spinach sauce with cherry tomatoes, fennel, feta and pine nuts", "price":"25.00" },' +
'{ "type":"food", "name":"RAVIOLI", "description":"filled with truffle-ricotta and hazelnuts butter", "price":"28.50" } ]'
);
const desserts = JSON.parse(
"[" +
'{ "type":"separator", "description":"SWEETS" },' +
'{ "type":"food", "name":"CHOCOLATE MOUSSE", "description":"with star anise, a pecan brownie and salty caramel sauce", "price":"12.00" },' +
'{ "type":"food", "name":"TIRAMISU", "description":"rolled rhubarb pistachio with vanilla strawberry amaretto sauce", "price":"13.50" },' +
'{ "type":"food", "name":"FRUIT SALAD", "description":"exotic fruits with tapioca pearls mango sorbet and homemade coconut liqueur", "price":"10.50" } ]'
);
const drinks = JSON.parse(
"[" +
'{ "type":"separator", "description":"WATER & SODA" },' +
'{ "type":"drink", "name":"SPARKLING WATER", "description":"5dl", "price":"4.50" },' +
'{ "type":"drink", "name":"STILL WATER", "description":"5dl", "price":"4.50" },' +
'{ "type":"drink", "name":"SODA", "description":"3dl", "price":"5.50" },' +
'{ "type":"drink", "name":"TAP WATER", "description":"", "price":"FREE" },' +
'{ "type":"separator", "description":"BEER" },' +
'{ "type":"drink", "name":"BADENER GOLD", "description":"3dl", "price":"4.80" },' +
'{ "type":"drink", "name":"BADENER GOLD", "description":"5dl", "price":"7.00" },' +
'{ "type":"drink", "name":"QUĂ–LLFRISCH", "description":"5dl", "price":"7.50" },' +
'{ "type":"drink", "name":"BIER PAUL 02", "description":"3.3dl", "price":"6.00" },' +
'{ "type":"separator", "description":"RED WINE" },' +
'{ "type":"drink", "name":"MERLOT DEL TICINO", "description":"1dl", "price":"7.00" },' +
'{ "type":"drink", "name":"BOLGHERI ROSSO", "description":"1dl", "price":"8.50" },' +
'{ "type":"drink", "name":"NERO D’AVOLA IGT", "description":"1dl", "price":"7.50" },' +
'{ "type":"drink", "name":"MONTE CASTANHEIRO", "description":"1dl", "price":"8.00" },' +
'{ "type":"separator", "description":"WHITE WINE & CHAMPAGNE" },' +
'{ "type":"drink", "name":"ST. SAPHORIN7", "description":"1dl", "price":"7.00" },' +
'{ "type":"drink", "name":"BASILICATA BIANCO", "description":"1dl", "price":"7.50" },' +
'{ "type":"drink", "name":"TAITTINGER BRUT", "description":"7.5dl", "price":"91.00" },' +
'{ "type":"separator", "description":"WHISKY" },' +
'{ "type":"drink", "name":"OBAN 14 YEARS", "description":"4cl", "price":"13.50" },' +
'{ "type":"drink", "name":"LAGAVULIN 16 YEARS", "description":"4cl", "price":"15.00" },' +
'{ "type":"drink", "name":"MACALLEN AMBER", "description":"4cl", "price":"16.00" },' +
'{ "type":"separator", "description":"HOT DRINKS" },' +
'{ "type":"drink", "name":"ESPRESSO", "description":"", "price":"4.50" },' +
'{ "type":"drink", "name":"CAFE LATTE", "description":"", "price":"4.50" },' +
'{ "type":"drink", "name":"TEA", "description":"", "price":"5.00" } ]'
);
/////////////////////////////////////////////////////////////////
let sl = 0;
let startersbutton = document.getElementById("startersbutton");
let mainsbutton = document.getElementById("mainsbutton");
let dessertsbutton = document.getElementById("dessertsbutton");
let drinksbutton = document.getElementById("drinksbutton");
let ni1 = document.getElementById("ni1");
let ni2 = document.getElementById("ni2");
let ni3 = document.getElementById("ni3");
let ni4 = document.getElementById("ni4");
startersbutton.addEventListener("click", (e) => {
setIndicator(0);
populateItems(starters);
});
mainsbutton.addEventListener("click", (e) => {
setIndicator(1);
populateItems(mains);
});
dessertsbutton.addEventListener("click", (e) => {
setIndicator(2);
populateItems(desserts);
});
drinksbutton.addEventListener("click", (e) => {
setIndicator(3);
populateItems(drinks);
});
function populateItems(items) {
let menu = document.querySelector(".menu");
menu.innerHTML = "";
for (i = 0; i < items.length; i++) {
if (items[i].type === "separator") {
let menuitem = document.createElement("div");
menuitem.setAttribute("class", "menu-separator");
menuitem.innerHTML = items[i].description;
menu.appendChild(menuitem);
}
if (items[i].type === "food") {
let menuitem = document.createElement("div");
let menuitemname = document.createElement("div");
let menuitemdesc = document.createElement("div");
let menuitemprize = document.createElement("div");
menuitem.setAttribute("class", "menu-item");
menuitemname.setAttribute("class", "menu-item-name");
menuitemdesc.setAttribute("class", "menu-item-description");
menuitemprize.setAttribute("class", "menu-item-price");
menuitemname.innerHTML = items[i].name;
menuitemdesc.innerHTML = items[i].description;
menuitemprize.innerHTML = items[i].price;
menuitem.appendChild(menuitemname);
menuitem.appendChild(menuitemdesc);
menuitem.appendChild(menuitemprize);
menu.appendChild(menuitem);
}
if (items[i].type === "drink") {
let drinkitem = document.createElement("div");
let drinkitemname = document.createElement("div");
let drinkitemdesc = document.createElement("div");
let drinkitemprize = document.createElement("div");
drinkitem.setAttribute("class", "drink-item");
drinkitemname.setAttribute("class", "drink-item-name");
drinkitemdesc.setAttribute("class", "drink-item-description");
drinkitemprize.setAttribute("class", "drink-item-price");
drinkitemname.innerHTML = items[i].name;
drinkitemdesc.innerHTML = items[i].description;
drinkitemprize.innerHTML = items[i].price;
drinkitem.appendChild(drinkitemname);
drinkitem.appendChild(drinkitemdesc);
drinkitem.appendChild(drinkitemprize);
menu.appendChild(drinkitem);
}
}
}
function setIndicator(sel) {
sl = sel;
let vp = "";
if (window.innerWidth < 800) {
vp = "60px";
} else {
vp = "85%";
}
let elems = [ni1, ni2, ni3, ni4];
for (i = 0; i < elems.length; i++) {
if (i === sel) {
elems[i].style.width = vp;
elems[i].style.boxShadow = "2px 2px 10px 2px var(--icolor" + (i + 1) + ")";
} else {
elems[i].style.width = "0";
elems[i].style.boxShadow = "none";
}
}
}
window.addEventListener("resize", (e) => {
setIndicator(sl);
});
//default runs
setIndicator(sl);
populateItems(starters);
Also see: Tab Triggers