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.
<h1 class="title">Sushi Calculator</h1>
<div class = "container">
<div>
<h1>Menu List</h1>
<div class = "search-container">
<input id = "searchbar" type = "text" onkeyup="searchList(this.value)" placeholder="Search me"><button id = "clearsearch" onclick="clearSearch()">X</button>
</div>
<ul id = "sushi-list"></ul>
</div>
<div>
<h1>List</h1>
<ol id = "sushi-cost-list"></ol>
<div id = "sushiTotal">
</div>
<button id = "clear">Clear</button>
</div>
</div>
<div class = "sushi-graphic">
<div class = "one"></div>
<div class = "one"></div>
<div class = "one"></div>
</div>
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
html{
margin:0;
padding:0;
height:100%;
}
body{
/*background:radial-gradient(#ffe0e5,#ffc0cb 40%,#ffe0e5 50%);
background-size:50px 50px;*/
background:url(https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2F4i16c1pbkzn1x79pv1y0zrpf-wpengine.netdna-ssl.com%2Fwp-content%2Fuploads%2F2017%2F02%2Freclaimed-v-groove-paneling_antique-chestnut-803x1030.jpg&f=1);
background-size:cover;
font-family: 'Montserrat', sans-serif;
margin:0;
height:100%;
}
.container{
margin-top:10px;
}
h1{
font-family: 'Montserrat', sans-serif;
background: linear-gradient(white 2%,pink 90%,salmon);
padding:5px;
margin:0;
font-size:20px;
border-bottom:2px solid white;
}
.title{
background:black;
color:pink;
}
#sushi-list{
height:250px;
overflow-y:scroll;
background:white;
margin-top:0;
list-style-type:none;
}
.search-container{
display:flex;
}
#searchbar{
border-radius:5px;
border:0px;
box-shadow:inset 0px 0px 2px grey;
height:30px;
text-indent:10px;
width:100%;
color:brown;
font-weight:bold;
font-size:18px;
font-family: 'Montserrat', sans-serif;
}
#clearsearch{
background:radial-gradient(white,pink);
border:0;
}
ul{
padding:0;
}
li{
padding:7px 0px 7px 5px;
border-bottom:0.2px solid lightgrey;
}
button{
vertical-align: middle;
cursor: pointer;
}
#sushi-list{
border:2px solid pink;
border-radius:0px 0px 10px 10px;
}
#sushi-list div{
float:right;
}
#sushi-list div button{
background:radial-gradient(white,pink);
border:0;
border-radius:5px;
width:25px;
padding:3px 0px;
margin:0px 2px;
font-size:15px;
}
#sushi-list div button:nth-child(1):before{
content:'-';
}
#sushi-list div button:nth-child(2):before{
content:'+';
}
#sushi-cost-list{
height:250px;
overflow-y:auto;
background:white;
margin-top:0px;
list-style-type:number;
padding:0px 0px 0px 25px;
border:2px solid pink;
border-radius:0px 0px 10px 10px;
}
#sushi-cost-list li div{
float:right;
margin-right:10px;
margin-top: -4px;
}
#sushi-cost-list li button{
border:0;
background:none;
}
#sushi-cost-list li button:before{
content:'x';
font-size:20px;
}
#sushiTotal{
background:white;
max-width:200px;
margin:1px 0px;
font-size:18px;
border-radius:5px;
}
#sushiTotal p{
padding:3px 10px;
}
#clear{
padding:10px 35px;
font-size:20px;
border:none;
border-radius:10px;
background:white;
border:2px solid pink;
}
.sushi-graphic{
position:absolute;
top:0;
width:100%;
height:100%;
z-index:-1;
}
.sushi-graphic .one:nth-child(1){
bottom:100px;
right:0;
}
.sushi-graphic .one:nth-child(2){
bottom:50px;
right:250px;
}
.sushi-graphic .one:nth-child(3){
bottom:0px;
right:500px;
}
.sushi-graphic .one{
background:black;
position:absolute;
width:200px;
height:200px;
bottom:0;
border-radius:50%;
display:flex;
justify-content:center;
align-items:center;
box-shadow:0px 0px 20px black;
}
.sushi-graphic .one::before{
content:'';
position:absolute;
background:radial-gradient(rgba(255,255,255,0.5),white,rgba(255,255,255,0.5)), radial-gradient(white,beige,white);
background-size:20px 20px, 10px 10px;
width:160px;
height:160px;
border-radius:50%;
}
.sushi-graphic .one::after{
content:'';
position:absolute;
background:linear-gradient(salmon,pink);
width:100px;
height:100px;
border-radius:50%;
}
@media only screen and (orientation: landscape){
.container{
display:flex;
}
.container > div{
width:100%;
margin:0px 10px;
}
}
var sushi = new Object();
var sushiCostArray = [];
sushi = {
"Asparagus Roll": 3.5,
"Cucumber Roll": 3.5,
"Squash Roll": 4,
"Avocado Roll": 3.5,
"Pickled Radish Roll": 4,
"Sweet Potato Roll" : 4,
"Sea Urchin Hand Roll": 7.5,
"Spicy Salmon Roll": 5.5,
"Salmon Roll": 5,
"Jade Roll": 8,
"Spicy Crunch Roll": 7,
"Boston Roll": 5.5,
"Dynamite Roll": 7,
"Crab Roll (Kani)": 4,
"Futo Maki (4 pieces)": 7,
"California Roll": 4.25,
"Yellowtail Roll": 5.5,
"Spicy Yellow tail Roll": 5.75,
"Salmon Skin Roll": 4.5,
"Eel Roll (Unagi)": 6,
"Tuna Roll (Tekkamaki)": 5,
"Spicy Tuna Roll": 5.5,
"Spider Roll": 8.5,
"American Dream Roll": 6.5,
"Crazy Horse Roll": 6.5,
"Philly Roll": 5.5,
"Spicy Calamari Roll": 6,
"Sushi King Roll": 14,
"Sea Dragon Roll 'No Rice'": 14.5,
"Mega Million Roll": 13,
"Neptune Roll": 14.5,
"Sunrise Roll": 9.5,
"Dragon in the Mist": 15.5,
"Atlantis Roll 'No Rice'": 11,
"Heart of Fire 'No Rice'": 9.5,
"Kraken Roll": 14.5,
"Pandora Roll": 14,
"Mango Fiesta": 13,
"Medusa Roll": 16.5,
"East Roll": 10.5,
"Tattoo Roll": 10,
"Snowy Roll": 10,
"Pink Lady Roll": 11.5,
"Dragon Roll": 9,
"Passion Roll": 9.5,
"Volcano Roll": 9.5,
"Triple Trouble Roll": 13,
"Aspen Roll": 9,
"Red Devil Roll": 10.5,
"Valentine Roll": 11,
"Dancing Eel Roll": 11,
"Ninja Roll": 9.75,
"Christmas Roll": 9.5,
"Fusion Roll": 12,
"Ocean Roll": 12,
"Mexican Roll": 7.5,
"Phoenix Roll": 10.5,
"Smokey Roll": 7.5,
"Kirin Roll": 8,
"Venus Roll": 12,
"Tropical Roll": 8,
"Rainbow Roll": 9,
"Caterpillar Roll": 7.5,
"Summer Roll": 7,
"Alaska Roll": 5.5,
"Stacy Roll": 9,
"Rutgers Roll": 11,
"Princeton Roll": 11,
"Johnny Roll": 9,
"Double A Roll": 10
}
var sushilist = document.getElementById("sushi-list");
var sushiCostList = document.getElementById("sushi-cost-list");
var sushiTotal = document.getElementById("sushiTotal");
var clearbutton = document.getElementById("clear");
var searchbar = document.getElementById("searchbar");
function ListSushiOptions(){
for(var rollName in sushi){
var listing = document.createElement("li");
var buttonholder = document.createElement("div");
var increaseSushi = document.createElement("button");
var increaseatt = document.createAttribute("onclick");
increaseatt.value = "increase(" + '"' + rollName + '"' + ")";
increaseSushi.setAttributeNode(increaseatt);
var decreaseSushi = document.createElement("button");
var att1 = document.createAttribute("onclick");
att1.value = "decrease(" + '"' + rollName + '"' + ")";
decreaseSushi.setAttributeNode(att1);
var textnode = document.createTextNode(rollName + ' ' + sushi[rollName]);
listing.appendChild(textnode);
sushilist.appendChild(listing);
listing.appendChild(buttonholder);
buttonholder.appendChild(decreaseSushi);
buttonholder.appendChild(increaseSushi);
}
}
ListSushiOptions();
function increase(rollName){
var sushiObject = {};
sushiObject["rollName"] = rollName;
sushiObject["rollPrice"] = sushi[rollName];
sushiCostArray.push(sushiObject);
calculateTotal();
printCostList();
}
function decrease(rollName){
for(var rollNumber in sushiCostArray){
if(sushiCostArray[rollNumber].rollName == rollName){
delete sushiCostArray[rollNumber];
break;
}
}
calculateTotal();
printCostList();
}
function printCostList(){
while (sushiCostList.firstChild) {
sushiCostList.removeChild(sushiCostList.firstChild);
}
for(var rollNumber in sushiCostArray){
var listing = document.createElement("li");
var textnode = document.createTextNode(sushiCostArray[rollNumber].rollName + ' ' + sushiCostArray[rollNumber].rollPrice);
listing.appendChild(textnode);
sushiCostList.appendChild(listing);
var buttonholder = document.createElement("div");
var decreaseSushi = document.createElement("button");
var att1 = document.createAttribute("onclick");
att1.value = "decrease(" + '"' + sushiCostArray[rollNumber].rollName + '"' + ")";
decreaseSushi.setAttributeNode(att1);
buttonholder.appendChild(decreaseSushi);
listing.appendChild(buttonholder);
}
}
function calculateTotal(){
while (sushiTotal.firstChild) {
sushiTotal.removeChild(sushiTotal.firstChild);
}
var total = 0;
for(var rollNumber in sushiCostArray){
total += sushiCostArray[rollNumber].rollPrice;
}
var totalListing = document.createElement("p");
var totalText = document.createTextNode("Total: $" + total);
totalListing.appendChild(totalText);
sushiTotal.appendChild(totalListing);
}
function clear(){
for(var rollNumber in sushiCostArray){
delete sushiCostArray[rollNumber];
}
calculateTotal();
printCostList();
}
function searchList(value){
var list = document.getElementById("sushi-list").getElementsByTagName("li");
value = value.toUpperCase();
for(let j=0; j < list.length; j++){
var listValue = (list[j]).textContent.toUpperCase();
if(listValue.search(value) >= 0){
list[j].style.display = 'block';
}else{
list[j].style.display = 'none';
}
}
}
function clearSearch(){
searchbar.value = "";
while (sushilist.firstChild) {
sushilist.removeChild(sushilist.firstChild);
}
ListSushiOptions();
}
clearbutton.addEventListener("click", clear);
Also see: Tab Triggers