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.
<main id="app">
<div class="bg-graphic"></div>
<section class="hero">
<div class="logo-wrapper">
<div class="logo-bar">
<div class="logo">
<h1 class="logotext">
<span class="purple">HEX</span
><span class="bigger-center-txt">2</span
><span class="red">R</span><span class="green">G</span
><span class="blue">B</span>
</h1>
</div>
<p class="tagline">An Animated Guide to Hex Codes</p>
</div>
</div>
<span id="header-animation">
<div class="hex-container">
<svg
id="blue"
class="blue header-animated-hex"
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 502.1 434.83"
>
<defs></defs>
<title></title>
<polygon
points="376.58 0 125.53 0 0 217.42 125.53 434.83 376.58 434.83 502.1 217.42 376.58 0"
/>
</svg>
<svg
id="red"
class="red header-animated-hex"
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 502.1 434.83"
>
<defs></defs>
<title></title>
<polygon
points="376.58 0 125.53 0 0 217.42 125.53 434.83 376.58 434.83 502.1 217.42 376.58 0"
/>
</svg>
<svg
id="green"
class="green header-animated-hex"
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 502.1 434.83"
>
<defs></defs>
<title></title>
<polygon
points="376.58 0 125.53 0 0 217.42 125.53 434.83 376.58 434.83 502.1 217.42 376.58 0"
/>
</svg>
</div>
<svg
id="motion-path-wrapper"
xmlns="http://www.w3.org/2000/svg"
viewBox="-0.95 -1.25 1045.05 263.23"
style="width:0; height:0;"
>
<defs></defs>
<title>path</title>
<path
id="motionPath"
d="M1.5,125.5c-8,465,1044-426,1044,0C1045.5,534.2,8.78-297.78,1.5,125.5Z"
/>
</svg>
</span>
<div class="intro">
<h2>
What are hex codes even?
</h2>
<span class="example-hex setBlack">
<span class="pwd">#</span>
<span class="red">95</span>
<span class="green">75</span>
<span class="blue">CD</span>
</span>
<p>
Hex codes are away to communicate a color value, to our browsers and eventually the computer. These are very similar to hsl and rgb values. Hsl and rgb have a clear and easy to read syntax. Hex codes unfortunately have a much more confusing syntax.
</p>
<div class="color-codes-example">
<span class="example">
<span class="">#</span>
<span class="">95</span>
<span class="">75</span>
<span class="">CD</span>
</span>
<span class="example">
<span class="pwd">rgb(</span>
<span class="">95,</span>
<span class="">75,</span>
<span class="">75</span>
<span class="pwd">)</span>
</span>
<span class="example">
<span class="pwd">hsl(</span>
<span class="">262%,</span>
<span class="">47%,</span>
<span class="">63%</span>
<span class="pwd">)</span>
</span>
</div>
<div class="divider from-guide">
<h3>Believe it or not its not all Globity-Gook!</h3>
<p>
Lets disect hex codes to make them easier to read and understand!
</p>
</div>
</div>
</section>
<section class="hex-16based">
<h2>Hex codes are made up of 16 possible values</h2>
<p>
Hex codes are comprised of 6 values that are apart of the hexidecimal system, or base 16. Instead of 10 values like we are used to (0-9), there are 16. Thats where those confusing letters come from.
</p>
<!-- show the animated 16 values-->
<div class="base-16-wheel">
<div class="wrapper">
<div class="bg"></div>
<div class="slide -0" style="--delay:0">F</div>
<div class="slide -1" style="--delay:-1">E</div>
<div class="slide -2" style="--delay:-2">D</div>
<div class="slide -3" style="--delay:-3">C</div>
<div class="slide -4" style="--delay:-4">B</div>
<div class="slide -5" style="--delay:-5">A</div>
<div class="slide -6" style="--delay:-6">9</div>
<div class="slide -7" style="--delay:-7">8</div>
<div class="slide -8" style="--delay:-8">7</div>
<div class="slide -9" style="--delay:-9">6</div>
<div class="slide -A" style="--delay:-10">5</div>
<div class="slide -B" style="--delay:-11">4</div>
<div class="slide -D" style="--delay:-12">3</div>
<div class="slide -E" style="--delay:-13">2</div>
<div class="slide -F" style="--delay:-14">1</div>
<div class="slide -F" style="--delay:-15">0</div>
</div>
<p>16 possible values</p>
</div>
<p>Each letter represents a number.</p>
<div class="letters2nums">
<ul class="">
<li>
<span class="letr">a </span>
<span class="num">10</span>
</li>
<li>
<span class="letr">b</span>
<span class="num">11</span>
</li>
<li>
<span class="letr">c</span>
<span class="num">12</span>
</li>
<li>
<span class="letr">d</span>
<span class="num">13</span>
</li>
<li>
<span class="letr">e</span>
<span class="num">14</span>
</li>
<li>
<span class="letr">f</span>
<span class="num">15</span>
</li>
</ul>
<p>Hover over the a letter to see its value.</p>
</div>
</section>
<section class="hex-pairing">
<h2>Thats Great and all, but how does that make colors</h2>
<div class="animated-hex-wrapper">
<span class="example-hex b-val-animated">
<span class="pwd">#</span>
<span class="red">95</span>
<span class="green">75</span>
<span class="blue">
<ul class="slide-down">
<li>2e</li>
<li>5f</li>
<li>75</li>
<li>a5</li>
</ul>
</span>
</span>
<div class="color-block"></div>
</div>
<p>
Hex codes are comprised of 6 values. There are 3 pairs of values in a hex code. The first two numbers show how much <span class="red">red</span> should be added. The next tell how much <span class="green">green</span>, and the next tells how much <span class="blue">blue</span> to add. This kind of sounds a lot like RGB.
</p>
</section>
<section class="hex-converts-to">
<h2>Under the hood</h2>
<p>
So we now know that hex codes are just pairs of values that represent <span class="red">red</span>, <span class="green">green</span>, and <span class="blue">blue</span> amounts. Which is kind of like rgb. Its actually even closer to rgb than just that. The values in hex code start at 0 and go to 255, just like in rgb.
</p>
</section>
<div class="divider from-user">
<h3>Enough theory how do we go from<br/> hex to rgb</h3>
</div>
<section class="algorithm">
<h2>Lets Get Converting</h2>
<div class="">
<span class="example-hex">#
<span class="red">E5</span>
<span class="green">73</span>
<span class="blue">73</span>
</span>
</div>
<p>Take this hex code for example</p>
<ol>
<li id="step-1">
<h4>Start with the first pair of values</h4>
<p>for us that is <span class="large-hex"><span class="inline">E5</span></span>
</p>
</li>
<li id="step-2">
<h4>Convert any letters to their hexdecimal value</h4>
<div class="letters2nums">
<ul class="">
<li>
<span class="letr">a </span>
<span class="num">10</span>
</li>
<li>
<span class="letr">b</span>
<span class="num">11</span>
</li>
<li>
<span class="letr">c</span>
<span class="num">12</span>
</li>
<li>
<span class="letr">d</span>
<span class="num">13</span>
</li>
<li>
<span class="letr">e</span>
<span class="num">14</span>
</li>
<li>
<span class="letr">f</span>
<span class="num">15</span>
</li>
</ul>
<p>Hover over the a letter to see its value.</p>
<div class="current-point">
<p>we now have</p>
<div class="value"><span class="val">14</span><span>and</span><span class="val">5</span></div>
</div>
</div>
</li>
<li id="step-3">
<h4 class="hctm">
Muiltiply one of the values by 16 to the power of the values place in the pair
</h4>
<span class="example-hex place-value">#
<span class="red"><span class="border" data-place="1">E</span> <span class="border" data-place="0">5</span></span>
<span class="green">73</span>
<span class="blue">73</span>
</span>
<p>
We are going to start with the 0's place, which for us is 5, and we will multiply this by
<span class="hint" data-hint="1">16<sup>0</sup></span>, since 5 is in the 0th place.
</p>
<div class="equation">
5 × 16<sup>0</sup> = 5
</div>
<p>
Next do the same for the E, which is in the 1s place. We will multiply E (which is equal to 14) by
<span class="hint" data-hint="16">16<sup>1</sup></span>
</p>
<div class="equation">
14 × 16<sup>1</sup> = 224
</div>
<div class="current-point">
<p>we now have</p>
<div class="value"><span class="val">224</span><span>and</span><span class="val">5</span></div>
</div>
</li>
<li id="step-4">
<h4>Now smush'em together</h4>
<div class="smushin-em">
<div class="smushem__wrapper">
<div class="left" style="--dir:1">
<div class="text">224</div>
</div>
<div class="right" style="--dir:-1">
<div class="text">5</div>
</div>
<div class="equates">229</div>
</div>
</div>
<p>
We will add our two values together to get the value of the amount red that will be in our color.
</p>
<div class="current-point">
<p>we now have</p>
<div class="value"><span class="val">229</span></div>
</div>
</li>
<li id="step-5">
<h4>Rinse, and Repeat</h4>
<p>
Now do the same for the <span class="green">green</span> and
<span class="blue">blue</span> pairs.
</p>
<p>
After completing the
<spand class="green">green</spand>and <span class="blue">blue</span> pairs. Check to see if you were correct below.
</p>
<span class="example-hex hover-results"><span class="pwd">#</span>
<span class="red results" style="--color:#e57373">
<span class="show-hex">E5</span>
<span class="show-res">229</span>
</span>
<span class="green results" style="--color:#a5d6a7">
<span class="show-hex">73</span>
<span class="show-res">115</span>
</span>
<span class="blue results" style="--color:#81d4fa">
<span class="show-hex">73</span>
<span class="show-res">115</span>
</span>
</span>
<p style="font-size:75%">hover to see the converted value.</p>
<div class="current-point">
<p>we now have</p>
<div class="value"><span class="val">rgb(229,115,115)</span></div>
</div>
</li>
</ol>
</section>
<div class="divider from-guide">
š
<h3>Great work, You did it!!!</h3>
</div>
<section class="converter">
<h2>In case you didnt do the math with us</h2>
<p>Here is a hex to rgb converter that uses the above algorithm.</p>
<div id="converter">
<h3>Hex 2 RGB Converter</h3>
<div class="converter__wrapper">
<div class="color-block">rgb(255,255,255)</div>
<div class="converter__hex">
<span class="hash">#</span> <input type="text" />
<button>convert</button>
</div>
<div class="error"></div>
</div>
</div>
</section>
<section class="take-away">
<h2>Take Aways!</h2>
<p>
Obviously RGB and HSL values are much easier to write and more human friendly than hex codes are. However, now you know that hex codes are not just some globity-gook mess only computers can read, and are really closley related to rgb. Now that you know the basics you can kind of guess that
#ff 00 00 is going to look red since is pair are the only ones that have a value, or #05ff22 is going to look greenish due how much green it has.
</p>
</section>
</main>
<svg viewBox="0 0 100 100" style="height:0; width:0;">
<filter id="goo">
<feGaussianBlur in="SourceGraphic" stdDeviation="20" result="blur" />
<feColorMatrix
in="blur"
mode="matrix"
result="goo"
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 60 -13"
/>
<feComposite in="SourceGraphic" in2="goo" />
</filter>
</svg>
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,400i,700");
//---------------------------------
//vars
$red: #c23838;
$purple: #9575cd;
$blue: #0774a6;
$green: #3a7e3c;
$yellow: #fff59d;
$grey: #eeeeee;
$lightGrey: #f5f5f5;
$darkGrey: #bdbdbd;
$black: #37474f;
$easing: cubic-bezier(0.5, 0, 0.5, 1);
$box-shadow: 0 0.5vmin 1vmin rgba(black, 0.1);
:root {
--shortTiming: 0.3s;
--timing: 1.5s;
--longTiming: 3s;
--converter-color: white;
}
//---------------------------------
//reset
body {
margin: 0;
padding: 0;
width: 100vw;
overflow-x: hidden;
box-sizing: border-box;
font-family: "Montserrat";
background: $lightGrey;
*,
*:after,
*:before {
box-sizing: inherit;
}
}
* {
position: relative;
}
//---------------------------------
.red {
color: $red;
fill: $red;
}
.green {
color: $green;
fill: $green;
}
.blue {
color: $blue;
fill: $blue;
}
.purple {
color: $purple;
}
//---------------------------------
html {
}
#app {
font-size: 1.3rem;
}
h1,
h2,
h3,
h4,
h5 {
color: $black;
}
h1 {
font-size: 4rem;
}
h2 {
font-size: 2.4rem;
@media (max-width: 600px) {
font-size: 1.9rem;
}
}
h3 {
font-size: 1.8rem;
}
h4 {
font-size: 1rem;
}
//---------------------------------
#app {
width: 100%;
height: auto;
section {
padding: 0 20px;
max-width: 900px;
width: 100%;
margin: 0 auto;
margin-bottom: 60px;
text-align: left;
&.hero {
max-width: 100%;
}
}
.divider {
margin-bottom: 60px;
}
}
//---------------------------------
//elements
//---------------------------------
.letters2nums {
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
font-size: 3rem;
@media (max-width: 600px) {
font-size: 2rem;
}
width: 100%;
justify-content: space-between;
overflow: hidden;
border-radius: 8px;
box-shadow: $box-shadow;
li {
width: 100%;
display: grid;
grid-template: 1fr/1fr;
* {
grid-row: 1/2;
grid-column: 1/2;
}
justify-content: center;
align-items: center;
}
.letr,
.num {
transition: all var(--shortTiming) $easing;
width: 100%;
height: 100%;
background: #000;
display: block;
color: white;
padding: 10px;
text-align: center;
}
.num {
background: $grey;
transform: translatey(100%);
color: $purple;
}
.letr {
background: $purple;
transform: translatey(0);
}
li:hover {
> .num {
transform: translatey(0);
}
> .letr {
transform: translatey(-100%);
}
}
}
}
.letters2nums > p {
color: $black;
font-size: 80%;
}
//---------------------------------
.example-hex {
display: inline-block;
margin-bottom: 5px;
$padding: 15px;
font-size: 2.5rem;
background: $grey;
padding: $padding;
//padding-right: $padding * 2;
box-shadow: $box-shadow;
border-radius: 8px;
&.setBlack > * {
color: $black;
}
span {
margin: 0px;
&.pwd {
color: $purple;
}
}
&.place-value {
padding-bottom: 20px;
.border {
border: 1px solid $purple;
line-height: 1;
padding: 0 5px;
display: inline-block;
//position:relative;
&:before {
filter: drop-shadow(0 0 2px rgba(black, 0.2));
content: attr(data-place)"'s place";
display: inline;
width: 200%;
position: absolute;
font-size: 10px;
border-radius: 4px;
color: white;
text-align: center;
padding: 7px;
background: $purple;
top: -75%;
left: -50%;
z-index: 1;
}
&:after {
position: absolute;
content: "";
height: 0;
width: 0px;
border-left: 4px solid transparent;
border-bottom: 8px solid $purple;
border-right: 4px solid transparent;
transform: rotate(180deg);
top: -18%;
left: 47%;
}
&:first-of-type {
&:before {
top: 120%;
left: -50%;
}
&:after {
top: 100%;
left: 40%;
transform: rotate(0);
}
}
}
}
}
//---------------------------------
.example {
display: flex;
justify-content: center;
$padding: 15px;
font-size: 1.5rem;
background: $grey;
padding: $padding;
box-shadow: $box-shadow;
border-radius: 8px;
color: $black;
}
.color-codes-example {
display: grid;
grid-template-rows: 1fr;
grid-template-columns: repeat(3, 1fr);
justify-content: center;
align-items: center;
grid-gap: 30px;
@media (max-width: 762px) {
grid-template-rows: repeat(3, 1fr);
grid-template-columns: minmax(150px, 300px);
}
> * {
text-align: center;
}
margin-top: 5vmin;
margin-bottom: 10vmin;
}
//---------------------------------
.divider {
position: relative;
max-width: 700px;
width: 80vw;
margin: 0 auto;
min-width: 300px;
border-radius: 8px;
padding: 10px 20px;
text-align: center;
background: $purple;
color: white;
filter: drop-shadow(0 1vmin 1vmin rgba(black, 0.2));
z-index: 1;
h3 {
color: white;
margin: 15px 0 10px;
}
&.from-guide:after {
position: absolute;
content: "";
height: 0;
width: 0px;
border-left: 25px solid transparent;
border-bottom: 50px solid $purple;
border-right: 25px solid transparent;
left: -20px;
bottom: 20px;
transform: rotate(-0.25turn) translateY(-10px);
z-index: 0;
}
&.from-user:after{
position: absolute;
content: "";
height: 0;
width: 0px;
border-left: 25px solid transparent;
border-bottom: 50px solid $purple;
border-right: 25px solid transparent;
right: -20px;
bottom: 20px;
transform: rotate(.25turn) translateY(-10px);
z-index: 0;
}
}
//---------------------------------
.hero {
.logo-bar,
.intro {
max-width: 900px;
width: 100%;
margin: 0 auto;
}
.logotext {
margin: 0;
font-size: 7rem;
@media (max-width: 600px) {
font-size: 3rem;
}
display: flex;
justify-content: center;
color: $black;
span {
z-index: 1;
}
.bigger-center-txt {
font-size: 150%;
margin: 0 -0.1em;
z-index: 0;
}
}
.logo-wrapper {
height: 35vh;
max-height:600px;
@media (max-width:600px){
max-height:300px;
}
min-height: 200px;
display: flex;
align-items: center;
background-image: radial-gradient(
farthest-corner at center bottom,
$lightGrey 40%,
rgba(255,255,255,0)
);
background-image: -webkit-radial-gradient(
farthest-corner at center bottom,
$lightGrey 40%,
transparent
);
}
h1.logotext {
margin-bottom: 0;
border-bottom: 1px solid $black;
display: inline-block;
}
.tagline {
margin-top: 10px;
font-size: 2.25rem;
@media (max-width: 600px) {
font-size: 1.1rem;
}
z-index: 10;
}
}
.intro {
//background: $lightGrey;
}
.bg-graphic {
opacity: 0.2;
top: -2.5rem;
left: -5px;
position: absolute;
width: 100%;
height: 35vh;
min-height: 200px;
background-size: contain;
background-image: url("http://my-codepen-assests.surge.sh/hexgraphic.aaeb676e.svg");
background-repeat: no-repeat;
}
//---------------------------------
.hex-16based {
display: grid;
grid-template: 1fr / 1fr minmax(100px, 250px);
@media (max-width: 600px) {
grid-template: auto / 100%;
}
grid-column-gap: 60px;
h2 {
grid-column: 1/-1;
}
> p {
grid-column: 1/2;
margin-top: 0;
}
.letters2nums {
grid-column: 1/2;
}
}
//---------------------------------
.algorithm ol {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, auto));
grid-gap: 20px;
padding: 0;
margin: 0;
counter-reset: steps;
& > li {
overflow: hidden;
counter-increment: steps;
&:before {
content: counter(steps);
position: absolute;
top: -25px;
left: 0px;
color: darken($grey, 5%);
font-size: 10rem;
line-height: 1;
}
list-style: none;
padding: 0;
margin: 0;
background: $grey;
padding: 20px;
// padding-top:10px;
border-radius: 8px;
box-shadow: $box-shadow;
h4 {
font-size: 1.5rem;
}
.large-hex {
line-height: 1;
margin-top: 15px;
font-size: 3rem;
display: block;
.inline {
border-radius: 8px;
padding: 7px;
display: inline-block;
background: white;
color: $black;
}
}
.letters2nums ul {
@media (max-width: 900px) {
font-size: 2rem;
}
}
&#step-1 {
p {
text-align: center;
}
}
&#step-3 {
grid-column: 1/-1;
.example-hex {
background: white;
}
}
&#step-4 {
.smushin-em {
display: flex;
justify-content: center;
align-items: center;
.smushem__wrapper {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
filter: url(#goo);
display: flex;
justify-content: space-around;
align-items: center;
}
height: 200px;
background: white;
border-radius: 8px;
.left,
.right,
.equates {
background: lighten($red, 20%);
color: $red;
width: 50px;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
}
.left,
.right {
animation: smush var(--longTiming) $easing infinite alternate;
@keyframes smush {
0%,
30% {
transform: none;
}
70% {
}
80%,
100% {
transform: translateX(calc(190% * var(--dir)));
}
}
.text {
animation: hideText var(--longTiming) linear infinite alternate;
@keyframes hideText {
0%,
30% {
opacity: 1;
}
80%,
100% {
opacity: 0;
}
}
}
}
.equates {
z-index: 2;
position: absolute;
left: 45%;
opacity: 0;
animation: reveal var(--longTiming) linear infinite alternate;
@keyframes reveal {
0% {
opacity: 0;
}
70% {
opacity: 0;
}
90%,
100% {
opacity: 1;
}
}
}
}
}
&#step-5 {
.hover-results {
height: 3.5rem;
.pwd {
padding: 5px;
color: white;
background: $black;
}
padding: 0 !important;
overflow: hidden;
display: flex;
align-items: center;
justify-content: space-between;
.results {
background: var(--color);
color: white;
width: 100%;
height: 100% !important;
text-align: center;
display: inline-block;
display: grid;
grid-template: 100%/ 100%;
> * {
grid-row: 1/-1;
grid-column: 1/-1;
}
.show-res,
.show-hex {
transition: all var(--shortTiming) $easing;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.show-res {
background: white;
color: var(--color);
transform: translateY(120%);
}
&:hover {
.show-hex {
transform: translateY(-120%);
}
.show-res {
transform: translateY(0%);
}
}
}
}
}
}
.current-point {
margin-top: 20px;
.val {
background: white;
display: inline-block;
margin: 5px;
}
text-align: center;
.value {
width: 75%;
margin: 0 auto;
}
p {
font-size: 50%;
margin: 0;
}
}
}
.equation {
font-size: 2rem;
border-radius: 8px;
background: white;
padding: 5px;
display: inline-block;
color: $black;
}
.hint {
display: inline-block;
background: lighten($purple, 30%);
border-bottom: 4px solid $purple;
&:after,
&:before {
transition: opacity 0.28s linear;
opacity: 0;
}
&:hover {
&:after,
&:before {
opacity: 1;
}
}
&:after {
position: absolute;
content: "";
height: 0;
width: 0px;
border-left: 4px solid transparent;
border-bottom: 8px solid $purple;
border-right: 4px solid transparent;
bottom: -30%;
left: 44%;
}
&:before {
filter: drop-shadow(0 0 2px rgba(black, 0.2));
content: "hint: its " attr(data-hint);
display: inline;
width: 250%;
position: absolute;
font-size: 10px;
border-radius: 4px;
color: white;
text-align: center;
padding: 7px;
background: $purple;
bottom: -117%;
left: -50%;
z-index: 1;
}
}
//---------------------------------
#header-animation {
z-index: 0;
position: absolute;
width: 100vw;
height: 600px;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
transform: scale(0.7);
}
.hex-container {
filter: url(#goo);
position: absolute;
transform-origin: top left;
left: 0%;
top: -15%;
width: 5rem;
#red {
animation: redHex 2s 0s linear infinite alternate;
}
#green {
animation: greenHex 2s 0s infinite alternate;
}
#blue {
animation: blueHex 3s 0s infinite alternate;
}
@keyframes redHex {
from {
transform: translate(0px, 0px);
}
to {
transform: translate(50px, 50px);
}
}
@keyframes blueHex {
0% {
transform: translate(0px, 0px);
}
50% {
transform: translate(50px, 0px);
}
100% {
transform: translate(0px, 50px);
}
}
@keyframes greenHex {
from {
transform: translate(0px, 0px);
}
to {
transform: translate(50px, 0px);
}
}
}
.header-animated-hex {
width: 1.5rem;
}
//animationated demonstrationss
//---------------------------------
.base-16-wheel {
display: flex;
justify-content: flex-start;
align-items: flex-start;
flex-direction: column;
.wrapper {
position: relative;
border-radius: 10%;
background: $grey;
box-shadow: 0 0.5vmin 1vmin rgba(black, 0.1);
height: 7.5rem;
width: 7.5rem;
display: grid;
grid-template: 1fr/1fr;
color: $darkGrey;
align-items: center;
overflow: hidden;
> * {
grid-row: 1/-1;
grid-column: 1/-1;
}
.slide {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 5rem;
animation: base-16-wheel 16s linear infinite;
animation-delay: calc(var(--delay) * 1s);
transform-origin: center 300%;
@keyframes base-16-wheel {
0% {
transform: rotate(-0.9turn);
}
11% {
transform: rotate(0turn);
}
15% {
transform: rotate(0turn);
}
25% {
transform: rotate(0.25turn);
}
100% {
transform: rotate(0.9turn);
}
}
}
}
}
//---------------------------------
//animated hex example
.animated-hex-wrapper {
display: flex;
height: 5rem;
> * {
margin: 0 0.5rem;
}
}
.b-val-animated {
> span:not(.pwd) {
background: currentcolor;
display: block;
padding: 5px;
&.red {
background: lighten($red, 20%);
}
&.blue {
background: lighten($blue, 20%);
}
&.green {
background: lighten($green, 20%);
}
}
.blue {
overflow: hidden;
}
display: flex;
justify-content: space-around;
max-width: 350px;
width: 300px;
height: 100%;
.slide-down {
margin: 0;
padding: 0;
display: grid;
grid-template: 1fr / 1fr;
> * {
grid-row: 1/-1;
grid-column: 1/-1;
}
li {
transition: all var(--shortTiming) $easing;
list-style: none;
transform: translateY(3rem);
&[data-active] {
transform: translatey(-3rem);
& + li {
transform: translateY(0rem);
}
}
}
}
}
.color-block {
width: 100px;
height: 100%;
background: var(--color-block-bg);
border-radius: 8px;
box-shadow: $box-shadow;
margin-bottom: 2rem;
}
//---------------------------------
//converter
#converter {
.error{
color:$red;
}
.color-block {
display: flex;
justify-content: center;
align-items: center;
background: var(--converter-color);
width: 300px;
height: 100px;
}
.converter__hex {
display: flex;
height: 4rem;
align-items: center;
border-radius: 8px;
max-width:400px;
overflow: hidden;
background: $black;
color: white;
.hash {
padding: 10px;
width: 30px;
display: inline-block;
}
input {
flex: 2;
min-width:100px;
height: 100%;
font-size: 2rem;
padding-left: 10px;
letter-spacing: 5px;
color: $black;
margin: 0;
}
button {
border:none;
margin: 0;
-webkit-appearance: button;
height: 100%;
flex:1;
background: $purple;
outline:none;
color: white;
font-size: 1rem;
&:hover {
background: $black;
}
}
}
}
//title animation
const path = MorphSVGPlugin.pathDataToBezier("#motionPath");
TweenMax.to(".hex-container", 25, {
bezier: { values: path, type: "cubic" },
ease: Linear.easeNone,
repeat: -1
});
///////////////-------////////
console.clear();
//animated hex example
const slideContainer = document.querySelector(".slide-down");
const slider = slideContainer;
const colorArray = ["#957575", "#9575A5", "#95752E", "#95755F"];
const anifn = () => {
const first = slider.querySelector("li");
document
.querySelectorAll("[data-active]")
.forEach(el => el.removeAttribute("data-active"));
first.setAttribute("data-active", true);
};
const changeColor = () => {
const hex = document.querySelectorAll();
};
let i = 0;
setInterval(() => {
const oldChild = slider.querySelector("li");
slider.removeChild(oldChild);
slider.append(oldChild);
anifn();
const block = document.querySelector(".color-block");
block.style.setProperty("--color-block-bg", `${colorArray[i]}`);
i++;
if (i > 3) {
i = 0;
}
}, 2000);
//////-----------//////////
//converter
const newError = msg => {
const errorTag = document.querySelector(".error");
errorTag.innerHTML = msg;
};
const removeError = () => {
const errorTag = document.querySelector(".error");
errorTag.innerHTML = "";
};
const base16 = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
a: 10,
b: 11,
c: 12,
d: 13,
e: 14,
f: 15
};
const convertBtn = document.querySelector("#converter button");
convertBtn.addEventListener("click", function() {
removeError();
const input = document.querySelector("#converter input").value;
if (input.length !== 6) return newError("must have exactly 6 values");
const hex = input.split("");
const r = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
const g = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
const b = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
if (isNaN(r) || isNaN(g) || isNaN(b)) {
return newError("not a valid Hexcode");
}
const block = document.querySelector("#converter .color-block");
function ccRGB(rgb) {
rgb = rgb.match(/\w+/g);
let r = 0.2126 * rgb[1],
g = 0.7152 * rgb[2],
b = 0.0722 * rgb[3];
return (r + g + b) >= 128 ? "black" : "white";
}
block.style.color = ccRGB(`rgb(${r}, ${g}, ${b})`);
block.style.setProperty("--converter-color", `rgb(${r} , ${g} , ${b})`);
block.innerHTML = window.getComputedStyle(block).backgroundColor;
});
Also see: Tab Triggers