“This is the fifth day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.
Growing up playing games on my GBA (especially Pokemon and Harvest Moon), I’ve always been fascinated by pixel art and its inherent retro look.When I started learning about HTML and CSS in September, one of the first attributes I discovered was that it allowed us to add shadow effects around elements.box-shadow
如MDNAs described, this property is described by X and Y offsets, blurring, diffusion radii, and color, all of which provide many opportunities for us to try and create different things. One of them is pixel art.
html部分
-------------------------------------------------------------------------------------
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=VT323">
<div class="back">
<div class="base">
<div class="base" id="two">
<div class="base" id="three">
<div class="base" id="four">
<div class="base" id="five">
<div class="pokeball" id="first"></div>
<div class="pokeball" id="second"></div>
<div class="pokeball" id="third"></div>
</div>
</div>
</div>
</div>
<div class="ash"></div>
</div>
<div class="base" id="dialogue">
<h1>Choose wisely!...</h1>
<div class="fwd"></div>
</div>
```
CSS部分
-------------------------------------------------------------------------------------
* {
margin: 0px;
padding: 0px;
}
.back {
width: 100vw;
height: 100vh;
background: #E8E8E8;
align-items: center;
justify-content: center;
font-size: 3em;
display: flex;
position: relative;
}
.base {
width: 60vmin;
height: 30vmin;
color: #A1A1A1;
background: black;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#two {
width: 63vmin;
height: 27vmin;
}
#three {
background: #575757;
width: 59vmin;
height: 25vmin;
}
#four {
width: 61vmin;
height: 22vmin;
box-shadow: 0 -2vmin black;
}
#five {
background: #999999;
width: 55vmin;
height: 18vmin;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
box-shadow:
0 -2vmin #999999,
-2vmin 0 white,
2vmin 0 white,
-2vmin -4vmin white,
2vmin -4vmin white
}
#dialogue {
position: absolute;
background: white;
top: 70vmin;
height: 25vmin;
width: 90vmin;
color: black;
box-shadow:
-1.5vmin 1.5vmin, 1.5vmin -1.5vmin,
-2.5vmin 2.5vmin white, -2.5vmin -2.5vmin white,
-1.5vmin -1.5vmin, 1.5vmin 1.5vmin
}
h1 {
font-family: VT323;
font-size: 12vmin;
text-align: left;
}
.fwd {
position: relative;
left: 35vmin;
top: 1vmin;
background: transparent;
height: 1vmin;
width: 1vmin;
color: black;
box-shadow:
1vmin 0, 2vmin 0, 3vmin 0, 4vmin 0, 5vmin 0, 6vmin 0,
2vmin 1vmin, 3vmin 1vmin, 4vmin 1vmin, 5vmin 1vmin,
3vmin 2vmin, 4vmin 2vmin;
animation: int 1s infinite;
}
.pokeball {
position: relative;
height: 1vmin;
width: 1vmin;
background: transparent;
color: white;
box-shadow:
5vmin 0 black, 6vmin 0 black, 7vmin 0 black, 8vmin 0 black,
3vmin 1vmin black, 4vmin 1vmin black, 5vmin 1vmin red, 6vmin 1vmin red, 7vmin 1vmin red, 8vmin 1vmin red, 9vmin 1vmin black, 10vmin 1vmin black,
2vmin 2vmin black, 3vmin 2vmin red, 4vmin 2vmin red, 5vmin 2vmin red, 6vmin 2vmin, 7vmin 2vmin, 8vmin 2vmin red, 9vmin 2vmin red, 10vmin 2vmin red, 11vmin 2vmin black,
2vmin 3vmin black, 3vmin 3vmin red, 4vmin 3vmin red, 5vmin 3vmin red, 6vmin 3vmin, 7vmin 3vmin, 8vmin 3vmin red, 9vmin 3vmin red, 10vmin 3vmin red, 11vmin 3vmin black,
1vmin 4vmin black, 2vmin 4vmin red, 3vmin 4vmin red, 4vmin 4vmin red, 5vmin 4vmin red, 6vmin 4vmin red, 7vmin 4vmin red, 8vmin 4vmin red, 9vmin 4vmin red, 10vmin 4vmin red, 11vmin 4vmin red, 12vmin 4vmin black,
1vmin 5vmin black, 2vmin 5vmin red, 3vmin 5vmin red, 4vmin 5vmin red, 5vmin 5vmin red, 6vmin 5vmin red, 7vmin 5vmin red, 8vmin 5vmin red, 9vmin 5vmin red, 10vmin 5vmin red, 11vmin 5vmin red, 12vmin 5vmin black,
1vmin 6vmin black, 2vmin 6vmin, 3vmin 6vmin, 4vmin 6vmin red, 5vmin 6vmin red, 6vmin 6vmin red, 7vmin 6vmin red, 8vmin 6vmin red, 9vmin 6vmin red, 10vmin 6vmin, 11vmin 6vmin, 12vmin 6vmin black,
1vmin 7vmin black, 2vmin 7vmin, 3vmin 7vmin, 4vmin 7vmin, 5vmin 7vmin, 6vmin 7vmin, 7vmin 7vmin, 8vmin 7vmin, 9vmin 7vmin, 10vmin 7vmin, 11vmin 7vmin, 12vmin 7vmin black,
2vmin 8vmin black, 3vmin 8vmin, 4vmin 8vmin, 5vmin 8vmin, 6vmin 8vmin, 7vmin 8vmin, 8vmin 8vmin, 9vmin 8vmin, 10vmin 8vmin, 11vmin 8vmin black,
2vmin 9vmin black, 3vmin 9vmin, 4vmin 9vmin, 5vmin 9vmin, 6vmin 9vmin, 7vmin 9vmin, 8vmin 9vmin, 9vmin 9vmin, 10vmin 9vmin, 11vmin 9vmin black,
3vmin 10vmin black, 4vmin 10vmin black, 5vmin 10vmin, 6vmin 10vmin, 7vmin 10vmin, 8vmin 10vmin, 9vmin 10vmin black, 10vmin 10vmin black,
5vmin 11vmin black, 6vmin 11vmin black, 7vmin 11vmin black, 8vmin 11vmin black;
}
.pokeball::after {
content: '';
position: absolute;
width: 1250%;
height: 1250%;
}
.pokeball:hover {
animation-name: shake;
animation-duration: 2s;
}
#first {
top: -18vmin;
left: -28vmin;
transform: scale(1.3, 1.3);
}
#second {
top: -19vmin;
left: -9vmin;
transform: scale(1.3, 1.3);
}
#third {
top: -20vmin;
left: 11vmin;
transform: scale(1.3, 1.3);
}
.ash {
position: relative;
height: 1vmin;
width: 1vmin;
background: transparent;
color: black;
top: -56vmin;
left: -10vmin;
transform: scale(1.3, 1.3);
box-shadow:
5vmin 0, 6vmin 0, 7vmin 0, 8vmin 0, 9vmin 0, 10vmin 0,
3vmin 1vmin, 4vmin 1vmin, 5vmin 1vmin #999999, 6vmin 1vmin #999999, 7vmin 1vmin #999999, 8vmin 1vmin #999999, 9vmin 1vmin #999999, 10vmin 1vmin #999999, 11vmin 1vmin, 12vmin 1vmin,
3vmin 2vmin, 4vmin 2vmin #999999, 5vmin 2vmin #999999, 6vmin 2vmin #999999, 7vmin 2vmin #999999, 8vmin 2vmin #999999, 9vmin 2vmin #999999, 10vmin 2vmin #999999, 11vmin 2vmin #999999, 12vmin 2vmin,
3vmin 3vmin, 4vmin 3vmin #999999, 5vmin 3vmin #999999, 6vmin 3vmin #999999, 7vmin 3vmin #999999, 8vmin 3vmin #999999, 9vmin 3vmin #999999, 10vmin 3vmin #999999, 11vmin 3vmin #999999, 12vmin 3vmin,
2vmin 4vmin, 3vmin 4vmin, 4vmin 4vmin, 5vmin 4vmin #999999, 6vmin 4vmin white, 7vmin 4vmin white, 8vmin 4vmin white, 9vmin 4vmin white, 10vmin 4vmin #999999, 11vmin 4vmin, 12vmin 4vmin, 13vmin 4vmin,
2vmin 5vmin, 3vmin 5vmin, 4vmin 5vmin white, 5vmin 5vmin, 6vmin 5vmin, 7vmin 5vmin, 8vmin 5vmin, 9vmin 5vmin, 10vmin 5vmin, 11vmin 5vmin white, 12vmin 5vmin, 13vmin 5vmin,
1vmin 6vmin, 2vmin 6vmin white, 3vmin 6vmin, 4vmin 6vmin white, 5vmin 6vmin white, 6vmin 6vmin white, 7vmin 6vmin white, 8vmin 6vmin white, 9vmin 6vmin white, 10vmin 6vmin white, 11vmin 6vmin white, 12vmin 6vmin, 13vmin 6vmin white, 14vmin 6vmin,
1vmin 7vmin, 2vmin 7vmin white, 3vmin 7vmin white, 4vmin 7vmin white, 5vmin 7vmin white, 6vmin 7vmin, 7vmin 7vmin white, 8vmin 7vmin white, 9vmin 7vmin, 10vmin 7vmin white, 11vmin 7vmin white, 12vmin 7vmin white, 13vmin 7vmin white, 14vmin 7vmin,
2vmin 8vmin, 3vmin 8vmin, 4vmin 8vmin white, 5vmin 8vmin white, 6vmin 8vmin, 7vmin 8vmin white, 8vmin 8vmin white, 9vmin 8vmin, 10vmin 8vmin white, 11vmin 8vmin white, 12vmin 8vmin, 13vmin 8vmin,
2vmin 9vmin, 3vmin 9vmin, 4vmin 9vmin, 5vmin 9vmin white, 6vmin 9vmin white, 7vmin 9vmin #999999, 8vmin 9vmin #999999, 9vmin 9vmin white, 10vmin 9vmin white, 11vmin 9vmin, 12vmin 9vmin, 13vmin 9vmin,
1vmin 10vmin, 2vmin 10vmin white, 3vmin 10vmin white, 4vmin 10vmin, 5vmin 10vmin, 6vmin 10vmin, 7vmin 10vmin, 8vmin 10vmin, 9vmin 10vmin, 10vmin 10vmin, 11vmin 10vmin, 12vmin 10vmin white, 13vmin 10vmin white, 14vmin 10vmin,
1vmin 11vmin, 2vmin 11vmin white, 3vmin 11vmin white, 4vmin 11vmin, 5vmin 11vmin, 6vmin 11vmin, 7vmin 11vmin, 8vmin 11vmin, 9vmin 11vmin, 10vmin 11vmin, 11vmin 11vmin, 12vmin 11vmin white, 13vmin 11vmin white, 14vmin 11vmin,
2vmin 12vmin, 3vmin 12vmin, 4vmin 12vmin, 5vmin 12vmin #999999, 6vmin 12vmin #999999, 7vmin 12vmin, 8vmin 12vmin, 9vmin 12vmin #999999, 10vmin 12vmin #999999, 11vmin 12vmin, 12vmin 12vmin, 13vmin 12vmin,
3vmin 13vmin, 4vmin 13vmin #999999, 5vmin 13vmin, 6vmin 13vmin, 7vmin 13vmin #999999, 8vmin 13vmin #999999, 9vmin 13vmin, 10vmin 13vmin, 11vmin 13vmin #999999, 12vmin 13vmin,
3vmin 14vmin, 4vmin 14vmin #999999, 5vmin 14vmin #999999, 6vmin 14vmin #999999, 7vmin 14vmin, 8vmin 14vmin, 9vmin 14vmin #999999, 10vmin 14vmin #999999, 11vmin 14vmin #999999, 12vmin 14vmin,
4vmin 15vmin, 5vmin 15vmin, 6vmin 15vmin, 7vmin 15vmin #6E6E6E, 8vmin 15vmin #6E6E6E, 9vmin 15vmin, 10vmin 15vmin, 11vmin 15vmin
}
@keyframes shake {
25% {
transform: rotate(-90deg);
transform: scale(1.3, 1.3);
transform-origin: 6vmin 6vmin;
}
50% {
transform: scale(1.5, 1.5);
}
}
@keyframes int {
25% {
top: 2vmin;
}
}
Copy the code
By creating a single HTML element and using the X and Y offsets of box shadows, we can start drawing with pixels. I’ll show you how to guide you through a few examples:
Create a pixel
We’ll start by creating an HTML element with the “Pixel” class. In our stylesheet, we will make the background transparent and start using box shadows. Since we are doing pixel art, we will assign 1px height and width. Here is our code and how it looks:
.pixel {
background: transparent;
height: 1px;
width: 1px;
box-shadow:
1px 0, 2px 0 red, 3px 0 green;
transform: scale(20);
}
Copy the code
As you can see, by creating a transparent 1px x 1px square, we can move the box shadow to the side and add color to “draw” using the pixel square. At this point, you might get a sense of where this is going. 😉
Creating Pixel Art
Looking closely at any pixel art, we will see how they are basically made up of colored pixel grids/matrices:
Since the box-shadow property allows us to add multiple box shadows when separated by commas, we will create our own grid of pixels. Let’s take this 9×8 pixel heart as an example:
To do this in code, we need to generate a 9×8 grid with box shadows (but only values with colors). By pressing the line from the top, our box shadow will look like this:
.pixel-heart {
color: red;
box-shadow:
/* 1st row */ 1px 0, 2px 0, 6px 0, 7px 0,
/* 2nd row */ 0 1px, 1px 1px, 2px 1px, 3px 1px, 5px 1px, 6px 1px, 7px 1px, 8px 1px,
/* 3rd row */ 0 2px, 1px 2px, 2px 2px, 3px 2px, 4px 2px, 5px 2px, 6px 2px, 7px 2px, 8px 2px,
/* 4th row */ 0 3px, 1px 3px, 2px 3px, 3px 3px, 4px 3px, 5px 3px, 6px 3px, 7px 3px, 8px 3px,
/* 5th row */ 1px 4px, 2px 4px, 3px 4px, 4px 4px, 5px 4px, 6px 4px, 7px 4px,
/* 6th row */ 2px 5px, 3px 5px, 4px 5px, 5px 5px, 6px 5px,
/* 7th row */ 3px 6px, 4px 6px, 5px 6px,
/* 8th row */ 4px 7px;
}
Copy the code
By declaring, we don’t have to enter every color for every pixel, and only add black: color: red to the pixels that represent the heart border
Now that we know how it works, it’s all a matter of choosing a model to recreate and partitioning it into a pixel matrix.
Make pixels scalable
In the examples I’ve shared so far, I’ve used this property directly to enlarge the pixels. Another approach is to use units of measurement for height and width so that our final size can be customized using different font sizes: transform: scale() ’em
.pup {
background: transparent;
font-size: 18px;
height: 1em;
width: 1em;
}
Copy the code
Animate our pixel art
Another thing we can do by simply adjusting the box shadow value is animation. To do this, we will change some of the values in the initial box shadow grid. keyframes
<div class="gameboy"></div>
Copy the code
* {
padding: 0;
margin: 0;
}
body {
background: #73FAC9;
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.gameboy {
margin-top: -55vmin;
margin-left: -35vmin;
background: transparent;
font-size: 2vmin;
height: 1em;
width: 1em;
color: #445291;
box-shadow:
1em 0 #004278, 2em 0 #004278, 3em 0 #004278, 4em 0 #004278, 5em 0 #004278, 6em 0 #004278, 7em 0 #004278, 8em 0 #004278, 9em 0 #004278, 10em 0 #004278, 11em 0 #004278, 12em 0 #004278, 13em 0 #004278, 14em 0 #004278, 15em 0 #004278, 16em 0 #004278, 17em 0 #004278,
0 1em #004278, 1em 1em #6974A7, 2em 1em #6974A7, 3em 1em, 4em 1em, 5em 1em, 6em 1em, 7em 1em, 8em 1em, 9em 1em, 10em 1em, 11em 1em, 12em 1em, 13em 1em, 14em 1em, 15em 1em, 16em 1em #364174
, 17em 1em #364174
, 18em 1em #004278,
0 2em #004278, 1em 2em #6974A7, 2em 2em #6974A7, 3em 2em #004278, 4em 2em #004278, 5em 2em #004278, 6em 2em #004278, 7em 2em #004278, 8em 2em #004278, 9em 2em #004278, 10em 2em #004278, 11em 2em #004278, 12em 2em #004278, 13em 2em #004278, 14em 2em #004278, 15em 2em #004278, 16em 2em #364174
, 17em 2em #364174
, 18em 2em #004278,
0 3em #004278, 1em 3em #6974A7, 2em 3em #004278, 3em 3em #707788, 4em 3em #707788, 5em 3em #707788, 6em 3em #707788, 7em 3em #707788, 8em 3em #707788, 9em 3em #707788, 10em 3em #707788, 11em 3em #707788, 12em 3em #707788, 13em 3em #707788, 14em 3em #707788, 15em 3em #707788, 16em 3em #004278, 17em 3em #364174
, 18em 3em #004278,
0 4em #004278, 1em 4em #6974A7, 2em 4em #004278, 3em 4em #707788, 4em 4em #707788, 5em 4em #E4E4E4, 6em 4em #E4E4E4, 7em 4em #E4E4E4, 8em 4em #E4E4E4, 9em 4em #E4E4E4, 10em 4em #E4E4E4, 11em 4em #E4E4E4, 12em 4em #E4E4E4, 13em 4em #E4E4E4, 14em 4em #707788, 15em 4em #707788, 16em 4em #004278, 17em 4em #364174
, 18em 4em #004278,
0 5em #004278, 1em 5em #6974A7, 2em 5em #004278, 3em 5em black, 4em 5em #707788, 5em 5em white, 6em 5em white, 7em 5em white, 8em 5em white, 9em 5em white, 10em 5em white, 11em 5em white, 12em 5em white, 13em 5em white, 14em 5em #707788, 15em 5em #707788, 16em 5em #004278, 17em 5em #364174, 18em 5em #004278,
0 6em #004278, 1em 6em #6974A7, 2em 6em #004278, 3em 6em #707788, 4em 6em #707788, 5em 6em white, 6em 6em white, 7em 6em white, 8em 6em white, 9em 6em white, 10em 6em white, 11em 6em white, 12em 6em white, 13em 6em white, 14em 6em #707788, 15em 6em #707788, 16em 6em #004278, 17em 6em #364174
, 18em 6em #004278,
0 7em #004278, 1em 7em #6974A7, 2em 7em #004278, 3em 7em #707788, 4em 7em #707788, 5em 7em white, 6em 7em white, 7em 7em white, 8em 7em white, 9em 7em white, 10em 7em white, 11em 7em white, 12em 7em white, 13em 7em white, 14em 7em #707788, 15em 7em #707788, 16em 7em #004278, 17em 7em #364174
, 18em 7em #004278,
0 8em #004278, 1em 8em #6974A7, 2em 8em #004278, 3em 8em #707788, 4em 8em #707788, 5em 8em white, 6em 8em white, 7em 8em white, 8em 8em white, 9em 8em white, 10em 8em white, 11em 8em white, 12em 8em white, 13em 8em white, 14em 8em #707788, 15em 8em #707788, 16em 8em #004278, 17em 8em #364174
, 18em 8em #004278,
0 9em #004278, 1em 9em #6974A7, 2em 9em #004278, 3em 9em #707788, 4em 9em #707788, 5em 9em white, 6em 9em white, 7em 9em white, 8em 9em white, 9em 9em white, 10em 9em white, 11em 9em white, 12em 9em white, 13em 9em white, 14em 9em #707788, 15em 9em #707788, 16em 9em #004278, 17em 9em #364174
, 18em 9em #004278,
0 10em #004278, 1em 10em #6974A7, 2em 10em #004278, 3em 10em #707788, 4em 10em #707788, 5em 10em white, 6em 10em white, 7em 10em white, 8em 10em white, 9em 10em white, 10em 10em white, 11em 10em white, 12em 10em white, 13em 10em white, 14em 10em #707788, 15em 10em #707788, 16em 10em #004278, 17em 10em #364174
, 18em 10em #004278,
0 11em #004278, 1em 11em #6974A7, 2em 11em #004278, 3em 11em #707788, 4em 11em #707788, 5em 11em white, 6em 11em white, 7em 11em white, 8em 11em white, 9em 11em white, 10em 11em white, 11em 11em white, 12em 11em white, 13em 11em white, 14em 11em #707788, 15em 11em #707788, 16em 11em #004278, 17em 11em #364174
, 18em 11em #004278,
0 12em #004278, 1em 12em #6974A7, 2em 12em #004278, 3em 12em #707788, 4em 12em #707788, 5em 12em #707788, 6em 12em #707788, 7em 12em #707788, 8em 12em #707788, 9em 12em #707788, 10em 12em #707788, 11em 12em #707788, 12em 12em #707788, 13em 12em #707788, 14em 12em #707788, 15em 12em #707788, 16em 12em #004278, 17em 12em #364174
, 18em 12em #004278,
0 13em #004278, 1em 13em #6974A7, 2em 13em #6974A7, 3em 13em #004278, 4em 13em #004278, 5em 13em #707788, 6em 13em #707788, 7em 13em #707788, 8em 13em #707788, 9em 13em #707788, 10em 13em #707788, 11em 13em #707788, 12em 13em #707788, 13em 13em #707788, 14em 13em #004278, 15em 13em #004278, 16em 13em #364174, 17em 13em #364174, 18em 13em #004278,
0 14em #004278, 1em 14em #6974A7, 2em 14em #6974A7, 3em 14em #6974A7, 4em 14em #6974A7, 5em 14em #004278, 6em 14em #004278, 7em 14em #004278, 8em 14em #004278, 9em 14em #004278, 10em 14em #004278, 11em 14em #004278, 12em 14em #004278, 13em 14em #004278, 14em 14em #364174, 15em 14em #364174, 16em 14em #364174, 17em 14em #364174, 18em 14em #004278,
0 15em #004278, 1em 15em #6974A7, 2em 15em #6974A7, 3em 15em #6974A7, 4em 15em #6974A7, 5em 15em, 6em 15em, 7em 15em, 8em 15em, 9em 15em, 10em 15em, 11em 15em, 12em 15em, 13em 15em, 14em 15em #364174, 15em 15em #364174, 16em 15em #364174, 17em 15em #364174, 18em 15em #004278,
0 16em #004278, 1em 16em #6974A7, 2em 16em #6974A7, 3em 16em #6974A7, 4em 16em #6974A7, 5em 16em, 6em 16em, 7em 16em, 8em 16em, 9em 16em, 10em 16em, 11em 16em, 12em 16em, 13em 16em, 14em 16em #364174, 15em 16em #364174, 16em 16em #364174, 17em 16em #364174, 18em 16em #004278,
0 17em #004278, 1em 17em #6974A7, 2em 17em #6974A7, 3em 17em #6974A7, 4em 17em black, 5em 17em black, 6em 17em, 7em 17em, 8em 17em, 9em 17em, 10em 17em, 11em 17em, 12em 17em, 13em 17em, 14em 17em #364174, 15em 17em black, 16em 17em black, 17em 17em #364174, 18em 17em #004278,
0 18em #004278, 1em 18em #6974A7, 2em 18em #6974A7, 3em 18em #6974A7, 4em 18em black, 5em 18em black, 6em 18em, 7em 18em, 8em 18em, 9em 18em, 10em 18em, 11em 18em, 12em 18em, 13em 18em, 14em 18em #364174, 15em 18em black, 16em 18em black, 17em 18em #364174, 18em 18em #004278,
0 19em #004278, 1em 19em #6974A7, 2em 19em black, 3em 19em black, 4em 19em black, 5em 19em black, 6em 19em black, 7em 19em black, 8em 19em, 9em 19em, 10em 19em, 11em 19em, 12em 19em black, 13em 19em black, 14em 19em #364174, 15em 19em #364174, 16em 19em #364174, 17em 19em #364174, 18em 19em #004278,
0 20em #004278, 1em 20em #6974A7, 2em 20em black, 3em 20em black, 4em 20em black, 5em 20em black, 6em 20em black, 7em 20em black, 8em 20em, 9em 20em, 10em 20em, 11em 20em, 12em 20em black, 13em 20em black, 14em 20em #364174, 15em 20em #364174, 16em 20em #364174, 17em 20em #364174, 18em 20em #004278,
0 21em #004278, 1em 21em #6974A7, 2em 21em #6974A7, 3em 21em #6974A7, 4em 21em black, 5em 21em black, 6em 21em, 7em 21em, 8em 21em, 9em 21em, 10em 21em, 11em 21em, 12em 21em, 13em 21em, 14em 21em #364174, 15em 21em #364174, 16em 21em #364174, 17em 21em #364174, 18em 21em #004278,
0 22em #004278, 1em 22em #6974A7, 2em 22em #6974A7, 3em 22em #6974A7, 4em 22em black, 5em 22em black, 6em 22em, 7em 22em, 8em 22em, 9em 22em, 10em 22em, 11em 22em, 12em 22em, 13em 22em, 14em 22em #364174, 15em 22em #364174, 16em 22em #364174, 17em 22em #364174, 18em 22em #004278,
0 23em #004278, 1em 23em #6974A7, 2em 23em #6974A7, 3em 23em #6974A7, 4em 23em #6974A7, 5em 23em, 6em 23em, 7em 23em, 8em 23em, 9em 23em, 10em 23em, 11em 23em, 12em 23em, 13em 23em, 14em 23em #364174, 15em 23em #364174, 16em 23em #364174, 17em 23em #364174, 18em 23em #004278,
0 24em #004278, 1em 24em #6974A7, 2em 24em #6974A7, 3em 24em #6974A7, 4em 24em #6974A7, 5em 24em, 6em 24em, 7em 24em, 8em 24em, 9em 24em, 10em 24em, 11em 24em, 12em 24em, 13em 24em, 14em 24em #364174, 15em 24em #364174, 16em 24em #364174, 17em 24em #364174, 18em 24em #004278,
0 25em #004278, 1em 25em #6974A7, 2em 25em #6974A7, 3em 25em #6974A7, 4em 25em #6974A7, 5em 25em, 6em 25em, 7em 25em black, 8em 25em black, 9em 25em, 10em 25em, 11em 25em black, 12em 25em black, 13em 25em, 14em 25em #364174, 15em 25em #364174, 16em 25em #364174, 17em 25em #364174, 18em 25em #004278,
0 26em #004278, 1em 26em #6974A7, 2em 26em #6974A7, 3em 26em #6974A7, 4em 26em, 5em 26em, 6em 26em, 7em 26em, 8em 26em, 9em 26em, 10em 26em, 11em 26em, 12em 26em, 13em 26em, 14em 26em #121527, 15em 26em #364174, 16em 26em #121527, 17em 26em #364174, 18em 26em #004278,
0 27em #004278, 1em 27em #6974A7, 2em 27em #6974A7, 3em 27em, 4em 27em, 5em 27em, 6em 27em, 7em 27em, 8em 27em, 9em 27em, 10em 27em, 11em 27em, 12em 27em, 13em 27em #121527, 14em 27em, 15em 27em #121527, 16em 27em #364174, 17em 27em #364174, 18em 27em #004278,
0 28em #004278, 1em 28em #6974A7, 2em 28em, 3em 28em, 4em 28em, 5em 28em, 6em 28em, 7em 28em, 8em 28em, 9em 28em, 10em 28em, 11em 28em, 12em 28em, 13em 28em, 14em 28em #121527, 15em 28em, 16em 28em #121527, 17em 28em #364174, 18em 28em #004278,
1em 29em #004278, 2em 29em, 3em 29em, 4em 29em, 5em 29em, 6em 29em, 7em 29em, 8em 29em, 9em 29em, 10em 29em, 11em 29em, 12em 29em, 13em 29em, 14em 29em, 15em 29em, 16em 29em, 17em 29em #004278,
2em 30em #004278, 3em 30em #004278, 4em 30em #004278, 5em 30em #004278, 6em 30em #004278, 7em 30em #004278, 8em 30em #004278, 9em 30em #004278, 10em 30em #004278, 11em 30em #004278, 12em 30em #004278, 13em 30em #004278, 14em 30em #004278, 15em 30em #004278, 16em 30em #004278,
/*shadow*/
19em 2em #5CC8A0,
19em 3em #5CC8A0, 19em 4em #5CC8A0, 19em 5em #5CC8A0, 19em 6em #5CC8A0, 19em 7em #5CC8A0, 19em 8em #5CC8A0, 19em 9em #5CC8A0, 19em 10em #5CC8A0, 19em 11em #5CC8A0, 19em 12em #5CC8A0, 19em 13em #5CC8A0, 19em 14em #5CC8A0, 19em 15em #5CC8A0, 19em 16em #5CC8A0, 19em 17em #5CC8A0, 19em 18em #5CC8A0, 19em 19em #5CC8A0, 19em 20em #5CC8A0, 19em 21em #5CC8A0, 19em 22em #5CC8A0, 19em 23em #5CC8A0, 19em 24em #5CC8A0, 19em 25em #5CC8A0, 19em 26em #5CC8A0, 19em 27em #5CC8A0, 19em 28em #5CC8A0, 19em 29em #5CC8A0,
20em 4em #5CC8A0, 20em 5em #5CC8A0, 20em 6em #5CC8A0, 20em 7em #5CC8A0, 20em 8em #5CC8A0, 20em 9em #5CC8A0, 20em 10em #5CC8A0, 20em 11em #5CC8A0, 20em 12em #5CC8A0, 20em 13em #5CC8A0, 20em 14em #5CC8A0, 20em 15em #5CC8A0, 20em 16em #5CC8A0, 20em 17em #5CC8A0, 20em 18em #5CC8A0, 20em 19em #5CC8A0, 20em 20em #5CC8A0, 20em 21em #5CC8A0, 20em 22em #5CC8A0, 20em 23em #5CC8A0, 20em 24em #5CC8A0, 20em 25em #5CC8A0, 20em 26em #5CC8A0, 20em 27em #5CC8A0, 20em 28em #5CC8A0, 20em 29em #5CC8A0,
18em 29em #5CC8A0, 17em 30em #5CC8A0, 18em 30em #5CC8A0, 19em 30em #5CC8A0, 20em 30em #5CC8A0,
3em 31em #5CC8A0, 4em 31em #5CC8A0, 5em 31em #5CC8A0, 6em 31em #5CC8A0, 7em 31em #5CC8A0, 8em 31em #5CC8A0, 9em 31em #5CC8A0, 10em 31em #5CC8A0, 11em 31em #5CC8A0, 12em 31em #5CC8A0, 13em 31em #5CC8A0, 14em 31em #5CC8A0, 15em 31em #5CC8A0, 16em 31em #5CC8A0, 17em 31em #5CC8A0, 18em 31em #5CC8A0, 19em 31em #5CC8A0,
4em 32em #5CC8A0, 5em 32em #5CC8A0, 6em 32em #5CC8A0, 7em 32em #5CC8A0, 8em 32em #5CC8A0, 9em 32em #5CC8A0, 10em 32em #5CC8A0, 11em 32em #5CC8A0, 12em 32em #5CC8A0, 13em 32em #5CC8A0, 14em 32em #5CC8A0, 15em 32em #5CC8A0, 16em 32em #5CC8A0, 17em 32em #5CC8A0, 18em 32em #5CC8A0;
}
.gameboy::after {
content: '';
position: absolute;
background: transparent;
height: 1em;
width: 1em;
color: transparent;
box-shadow:
3em 5em,
7em 6em, 7em 7em, /*1st bar*/
8em 6em, 8em 7em, /*2nd bar*/
9em 6em, 9em 7em, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em, 9em 9em, 10em 9em;
animation: turn-on 1.5s infinite;
}
@keyframes turn-on {
5% {
box-shadow:
3em 5em red,
7em 6em, 7em 7em, /*1st bar*/
8em 6em, 8em 7em, /*2nd bar*/
9em 6em, 9em 7em, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em, 9em 9em, 10em 9em;
}
10% {
box-shadow:
3em 5em red,
7em 6em yellow, 7em 7em yellow, /*1st bar*/
8em 6em, 8em 7em, /*2nd bar*/
9em 6em, 9em 7em, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
15% {
box-shadow:
3em 5em red,
7em 6em orange, 7em 7em orange, /*1st bar*/
8em 6em yellow, 8em 7em yellow, /*2nd bar*/
9em 6em, 9em 7em, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
20% {
box-shadow:
3em 5em red,
7em 6em deeppink, 7em 7em deeppink, /*1st bar*/
8em 6em orange, 8em 7em orange, /*2nd bar*/
9em 6em yellow, 9em 7em yellow, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
25% {
box-shadow:
3em 5em red,
7em 6em greenyellow, 7em 7em greenyellow, /*1st bar*/
8em 6em deeppink, 8em 7em deeppink, /*2nd bar*/
9em 6em orange, 9em 7em orange, /*3rd bar*/
10em 6em yellow, 10em 7em yellow, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
30% {
box-shadow:
3em 5em red,
7em 6em blue, 7em 7em blue, /*1st bar*/
8em 6em greenyellow, 8em 7em greenyellow, /*2nd bar*/
9em 6em deeppink, 9em 7em deeppink, /*3rd bar*/
10em 6em orange, 10em 7em orange, /*4th bar*/
11em 6em yellow, 11em 7em yellow, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
35% {
box-shadow:
3em 5em red,
7em 6em blue, 7em 7em blue, /*1st bar*/
8em 6em blue, 8em 7em blue, /*2nd bar*/
9em 6em greenyellow, 9em 7em greenyellow, /*3rd bar*/
10em 6em deeppink, 10em 7em deeppink, /*4th bar*/
11em 6em orange, 11em 7em orange, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
40% {
box-shadow:
3em 5em red,
7em 6em blue, 7em 7em blue, /*1st bar*/
8em 6em blue, 8em 7em blue, /*2nd bar*/
9em 6em blue, 9em 7em blue, /*3rd bar*/
10em 6em greenyellow, 10em 7em greenyellow, /*4th bar*/
11em 6em deeppink, 11em 7em deeppink, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
45% {
box-shadow:
3em 5em red,
7em 6em blue, 7em 7em blue, /*1st bar*/
8em 6em blue, 8em 7em blue, /*2nd bar*/
9em 6em blue, 9em 7em blue, /*3rd bar*/
10em 6em blue, 10em 7em blue, /*4th bar*/
11em 6em greenyellow, 11em 7em greenyellow, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
50% {
box-shadow:
3em 5em red,
7em 6em blue, 7em 7em blue, /*1st bar*/
8em 6em blue, 8em 7em blue, /*2nd bar*/
9em 6em blue, 9em 7em blue, /*3rd bar*/
10em 6em blue, 10em 7em blue, /*4th bar*/
11em 6em blue, 11em 7em blue, /*5th bar*/
8em 9em black, 9em 9em black, 10em 9em black;
}
60% {
box-shadow:
3em 5em red,
7em 6em, 7em 7em, /*1st bar*/
8em 6em, 8em 7em, /*2nd bar*/
9em 6em, 9em 7em, /*3rd bar*/
10em 6em, 10em 7em, /*4th bar*/
11em 6em, 11em 7em, /*5th bar*/
8em 9em, 9em 9em, 10em 9em;
}
}
Copy the code
Looking at the GameBoy box shadows can be overwhelming, but for now we’ll just focus on the animation. Assuming we’ve created a grid of box shadows, it all boils down to adjusting the values we want at different rates in the keyframes.
To mimic the effect of opening the GameBoy, I created a fake element at the top of the entire grid. This is to avoid copying and pasting the entire box shadow for each percentage of the animation. This pseudo-element is the entire screen when opened, and what we’re going to do is make it appear gradually, pixel by pixel in color:
@keyframes turn-on { 50% { box-shadow: 3em 5em red, 7em 6em blue, 7em 7em blue, /*1st bar*/ 8em 6em blue, 8em 7em blue, /*2nd bar*/ 9em 6em blue, 9em 7em blue, /*3rd bar*/ 10em 6em blue, 10em 7em blue, /*4th bar*/ 11em 6em blue, 11em 7em blue, /*5th bar*/ 8em 9em black, 9em 9em black, 10em 9em black; }}Copy the code
To simplify things
I know that typing a value after a value seems like a lot of work, so to make it easier (besides copying and pasting lines), one of our options is to use SCSS for variables and mappings, which I’ll try to explain with different examples in an upcoming article.
If this is still too much trouble for you, JValen has created a tool that generates a grid of box shadows for your pixel art creations. Then, all you need to do is adjust accordingly. 😉
I hope you found this article useful and inspired you to create your own. If you do, please share! If you come up with another way, I’d love to know!
You can find the rest of my CSS art on my CodePen, and follow me on 999fin.com for more updates.