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.
<header>
<h1 id="title">Online Guitar Tuner</h1>
<a class="josetxu" href="https://josetxu.com/" target="_blank">josetxu.com</a>
</header>
<section id="guitarBody">
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s6"></button>
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s5"></button>
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s4"></button>
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s3"></button>
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s2"></button>
<button onmouseover="pickString(this.id)" onclick="clickString(this.id)" class="string" id="s1"></button>
<div class="notes">
<span class="lightOff" id="s6Note">E<span class="notas">MI</span></span>
<span class="lightOff" id="s5Note">A<span class="notas">LA</span></span>
<span class="lightOff" id="s4Note">D<span class="notas">RE</span></span>
<span class="lightOff" id="s3Note">G<span class="notas">SOL</span></span>
<span class="lightOff" id="s2Note">B<span class="notas">SI</span></span>
<span class="lightOff" id="s1Note">E<span class="notas">MI</span></span>
</div>
</section>
<footer>
<button onclick="stopStrings()" class="inactive" id="btnStop">STOP</button>
<button onclick="usePick()" class="inactive" id="btnPick">PICK</button>
<button onclick="holdSound()" class="inactive" id="btnHold">HOLD</button>
</footer>
body {
background: url(https://cdn.josetxu.com/img/ogt-bg.jpg)repeat center center #000;
font-family: Arial, Helvetica, San-serif;
margin:0;
outline: none;
}
header {
height: 13vh;
color: #151515;
text-align: center;
margin: 0;
padding: 0.5vh;
box-shadow: 0 0 25px 5px #000;
box-sizing: border-box;
border-bottom: 1px solid #111;
background:url(https://cdn.josetxu.com/img/ogt-metal.jpg) repeat-x center center / contain transparent;
position: relative;
}
h1 {
margin: 0.5vh 0;
font-size: 2em;
padding: 3vh 0;
background-color: #333333;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(255,255,255,0.5) 0px 1px 3px;
}
h1#title.imgTitle{
text-shadow: 0 0 25px rgba(20, 139, 255, 0.8), 0 0 15px rgba(30, 144, 255, 0.54);
background-color: rgba(77, 134, 189, 0.8);
}
a.josetxu {
position: absolute;
right: 0px;
top: 10px;
text-decoration: none;
font-size: 10px;
color: #333;
width: 33%;
opacity: 0.5;
margin: 0 33%;
}
a.josetxu:hover {
opacity:1;
}
section {
margin: 0 auto;
float: none;
height: 72vh;
background: url(https://cdn.josetxu.com/img/ogt-pickup.png) no-repeat center 50% transparent;
width: 360px;
box-sizing: border-box;
}
button.string {
border: none;
float: left;
width: 40px;
margin: 0 7px 0 7px;
height: inherit;
outline: none;
cursor: pointer;
padding: 0 !important;
z-index: 1;
}
button.string:first-child {
margin-left: 26px !important;
}
button#s6, button#s4, button#s4, button#s3, button#s1 {
margin-left: 6px;
}
button#s2 {
margin-left: 8px;
}
#guitarBody button {
background-repeat:repeat-y ;
background-position:center center;
background-color:transparent;
}
#s1 {
background-image: url(https://cdn.josetxu.com/img/ogt-1.png); /*1.png*/
}
#s2 {
background-image: url(https://cdn.josetxu.com/img/ogt-2.png);
}
#s3 {
background-image: url(https://cdn.josetxu.com/img/ogt-3.png);
}
#s4 {
background-image: url(https://cdn.josetxu.com/img/ogt-4.png);
}
#s5 {
background-image: url(https://cdn.josetxu.com/img/ogt-5.png);
}
#s6 {
background-image: url(https://cdn.josetxu.com/img/ogt-6.png);
}
#s1:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-1.png), url(https://cdn.josetxu.com/img/ogt-1.png); /*brillo1|1.png*/
}
#s2:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-1.png), url(https://cdn.josetxu.com/img/ogt-2.png);
}
#s3:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-2.png), url(https://cdn.josetxu.com/img/ogt-3.png);
}
#s4:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-2.png), url(https://cdn.josetxu.com/img/ogt-4.png);
}
#s5:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-3.png), url(https://cdn.josetxu.com/img/ogt-5.png);
}
#s6:hover {
background-image: url(https://cdn.josetxu.com/img/ogt-shine-3.png), url(https://cdn.josetxu.com/img/ogt-6.png);
}
#guitarBody button.string.playingSound {
background-repeat:repeat-y, repeat-y, no-repeat !important;
background-position:center center, center center, center 50% !important;
background-color:transparent;
}
#s1.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-2.gif), url(https://cdn.josetxu.com/img/ogt-shine-1.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
#s2.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-3.gif), url(https://cdn.josetxu.com/img/ogt-shine-1.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
#s3.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-3.gif), url(https://cdn.josetxu.com/img/ogt-shine-1.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
#s4.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-4.gif), url(https://cdn.josetxu.com/img/ogt-shine-2.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
#s5.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-5.gif), url(https://cdn.josetxu.com/img/ogt-shine-2.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
#s6.string.playingSound {
background-image: url(https://cdn.josetxu.com/gif/ogt-6.gif), url(https://cdn.josetxu.com/img/ogt-shine-3.png), url(https://cdn.josetxu.com/img/ogt-light.png);
}
/******** CONTROLS *******/
footer {
margin: 0;
background-color: hsl(0,0%,90%);
height: 15vh;
text-align:center;
bottom: 0;
position: relative;
width: 100%;
background:url(https://cdn.josetxu.com/img/ogt-metal.jpg) repeat-x center center / contain transparent;
box-shadow: 0 0 25px 5px #000;
}
footer button {
font-size: 0;
height: 9vh;
width: 140px;
margin: 3vh 1vh 0;
border: none;
outline: none;
font-weight: bold;
color: transparent;
cursor: pointer;
text-align: center;
}
/******* buttons ******/
#btnStop {
background: url(https://cdn.josetxu.com/img/ogt-switch-off.png) no-repeat center right /contain;
text-align: left;
}
#btnHold {
background: url(https://cdn.josetxu.com/img/ogt-switch-off.png) no-repeat center left /contain;
text-align: right;
}
#btnHold:after , #btnStop:before {
content: "HOLD";
font-size: 18px;
background-color: #333333;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(255,255,255,0.5) 0px 1px 3px;
}
#btnStop:before {
content: "STOP";
}
#btnHold.active:after, #btnHold:active:after {
text-shadow: 0px 1px 3px rgba(255,255,255,0.3), 0 0 15px #59a0f4, 0 0 20px #59a0f4, 0 0 25px #59a0f4, 0 0 30px #59a0f4, 0 0 35px #59a0f4;
color: #1e90ff;
}
#btnStop:active:before {
text-shadow: rgba(255,255,255,0.5) 0px 1px 3px, 0 0 15px #ff0000, 0 0 20px #ff0000, 0 0 25px #ff0000;
color: #ff0000;
}
#btnStop:active {
background: url(https://cdn.josetxu.com/img/ogt-switch-stop.png) no-repeat center right /contain;
}
#btnHold.active, #btnHold:active {
background: url(https://cdn.josetxu.com/img/ogt-switch-hold.png) no-repeat center left /contain;
}
/****** pick *****/
#btnPick {
background: url(https://cdn.josetxu.com/img/ogt-pick-off.png) no-repeat center center /contain;
width: 100px;
font-size: 22px;
}
#btnPick.active{
background: url(https://cdn.josetxu.com/img/ogt-pick-on.png) no-repeat center center /contain;
}
section.pickActive , section.pickActive .string{
cursor: url(https://cdn.josetxu.com/img/ogt-pick.png)10 60, auto;
}
/* NOTES */
.notes {
position: absolute;
width: 330px;
top: 22%;
z-index: -1;
margin-left: 20px;
}
.notes span {
width: 50px;
display: inline-block;
color: #171717;
text-align: center;
font-size: 50px;
z-index: 0;
text-shadow: -1px -1px 1px #000000, 0px 0px 1px #6f6f6f;
}
.notes .lightOn, .notes .lightOn span {
color: #71abeb;
text-shadow: 0px 0px 15px #3779c5, 0px 0px 25px #3779c5, 0px 0px 35px #71abeb, -1px -1px 1px #000000, 0px 0px 1px #6f6f6f;
transition: all 0.2s ease;
}
.notas {
font-size: 22px !important;
margin-top: 42vh;
}
/* MEDIA QUERIES */
@media only screen and (max-width: 380px){
section {
margin-left: 0;
}
}
@media only screen and (max-width: 359px){
section {
margin-left: 0px;
background-position-x: -26px;
}
}
@media only screen and (max-width: 320px){
section {
width: 320px;
padding-left: 5px;
box-sizing: border-box;
margin-right: 0;
background-position-x: -21px;
}
.notes {
width: 320px;
margin-left: 0px;
}
.notes span {
width: 48px;
}
button.string:first-child {
margin-left: 0 !important;
}
button.string:last-child {
margin-right: 0!important;
}
}
/* Hide Pick if we have an inaccurate pointing device */
@media (pointer:coarse) {
#btnPick {
display:none !important;
}
}
/* Hide Pick if orientation is portrait (vertical)*/
@media only screen and (orientation : portrait) {
#btnPick {
display:none !important;
}
}
/* VARIABLES */
/* sounds */
var s1 = new Audio('https://cdn.josetxu.com/audio/guitar-string-1.mp3');
var s2 = new Audio('https://cdn.josetxu.com/audio/guitar-string-2.mp3');
var s3 = new Audio('https://cdn.josetxu.com/audio/guitar-string-3.mp3');
var s4 = new Audio('https://cdn.josetxu.com/audio/guitar-string-4.mp3');
var s5 = new Audio('https://cdn.josetxu.com/audio/guitar-string-5.mp3');
var s6 = new Audio('https://cdn.josetxu.com/audio/guitar-string-6.mp3');
/* FUNCTIONS */
/* short getElementById */
function elem(id){
var element = document.getElementById(id);
return element;
}
/* tuner functions */
function pickString(thisString){
if(pick == true) clickString(thisString);
}
function clickString(thisString) {
elem('title').className='imgTitle';
elem(thisString).className = "string";
window[thisString].currentTime = 0;
window[thisString].play();
var thisNote = thisString+"Note";
elem(thisString).className = "string playingSound";
elem(thisNote).className = "lightOn";
setTimeout(function(){
if(window[thisString].loop != true){
elem(thisString).className = "string";
elem(thisNote).className = "lightOff";
if(document.querySelectorAll('.playingSound').length==0){
elem('title').className='';
}
}
}, 4500);
}
function holdSound(){
if(s1.loop != true){
s1.loop = s2.loop = s3.loop = s4.loop = s5.loop = s6.loop = true;
elem('btnHold').className = "active";
} else {
s1.loop = s2.loop = s3.loop = s4.loop = s5.loop = s6.loop = false;
elem('btnHold').className = "inactive";
s1.pause(); s2.pause(); s3.pause(); s4.pause(); s5.pause(); s6.pause();
stopStrings();
}
}
function stopStrings(){
elem('title').className='';
s1.pause(); s2.pause(); s3.pause(); s4.pause(); s5.pause(); s6.pause();
var auxString = document.querySelectorAll('.playingSound');
for (var x in auxString) {
if(auxString[x]!==undefined){
auxString[x].className = "string";
}
}
var auxNote = document.querySelectorAll(".lightOn");
for (x in auxNote) {
if(auxNote[x]!==undefined){
auxNote[x].className = "lightOff";
}
}
}
function usePick(){
var x = elem('btnPick').className;
if(x == 'inactive'){
elem('btnPick').className = 'active';
pick = true;
elem("guitarBody").className = 'pickActive';
} else {
elem('btnPick').className = 'inactive';
pick = false;
elem("guitarBody").className = '';
}
}
/* ON LOAD */
(function() {
setTimeout(function(){
clickString('s3');
}, 500);
})();
Also see: Tab Triggers