CSS Ugly Sweater: R2D2, We wish you a Merry Christmas
Tags: css, tutorial, frontend, art
Published: 2022-12-13 14:47:22

It's CSS Ugly Sweater season. The past two years I've made CSS projects based off of Ugly Sweaters. The inspiration came from a 2020 LEGO Star Wars Advent Calendar that had a minifig in a sweater. Since then I've made sweaters of Star Wars, Pokemon and Halloween.

This year the December 9th LEGO advent calendar gift was C3PO wearing a sweater of R2D2. That is the basis of today's art.

Since today's art is R2D2 listen to this while you read. See if you can guess the famous singer on this track.

{% embed https://youtu.be/KAQ-VZUdiqg %}

## Previously on Ugly Sweaters ##

![LEGO Stormtrooper wearing
 a blue sweater. The sweater has the imperial crest on it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8d2uwxcpw095jw1sz2sk.jpg)

I reused the basic sweater HTML from previous years. I changed the CSS for a darker blue sweater. I also changed the row of boxes to red and white.  

A previous blog post with more detail on the sweater construction is in [this post](https://dev.to/jarvisscript/ugly-sweater-css-36am). Below is the stub code for overall HTML structure.

```html
<div class="main">	
	<div class="flex-container">
	
	<div class="sweater">
	    <div class=“torso">
                <div class="character">
		   <div class="R2D2”></div>
                </div character>
            </div torso>
	</div sweater> 
       
       </div flex-container>
 </div main>

```

That's the sweater torso. I placed a character div in that torso. Inside the character div, is a div for a specific character. For this project it has a class of R2D2.

```css
:root {
	--sweaterblue: #105fa2;
	--droidblue: rgb(85 143 191 / 32%);

}

.R2D2 {
	display: flex;
	justify-content: center;
	align-items: center; 
	overflow: hidden;
	flex-direction: column;
}

```

```html
	   <div class="character">
		<div class="R2D2"></div>
	   </div>
	
```


##Are these the Droids you are looking for? ##


![C3PO wearing and R2D2 sweater.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xc3xzyackd6y0cm9fgq5.jpg)


## R2's Head


![Outline of a dome shape.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5bkztx5qftjsg76w9vx.jpg)

The head is a rectangle with border radius applied to the top corners but not the bottom corners. That creates the curved dome with a straight edge at the bottom.

The eye and projector lens are squares made to circles with 50% border radius. 

```html
	<div class="head">
		<div class="eye"></div>
		<div class="projector"></div>
	</div>
```

```css
.head {
	background-color: var(--droidblue);
	height: 80px;
	width: 200px;
	border-top-left-radius: 50%;
	border-top-right-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center; 
	overflow: hidden;
	flex-direction: column;
	border: 4px solid white;
	border-bottom: 1px solid white;
}

.eye {
	height: 20px;
	width: 20px;
	border: 6px solid white;
	background-color: white;
	border-radius: 50%;
}

.projector {
	height: 14px;
	width: 14px;
	background-color: white;
	border-radius: 50%;
	margin-left: 68px;
}
``` 

## Body

![droid head and body. looks like a circular trash can](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7o3m3tsop32u981if91.jpg)

The main body or droidTorso div is inside the legs div. It was cleaner to position it that way. The legs div is a modified square the bottom border is transparent so it doesn't show on screen.

```html
	<div class="legs">
		<div class="droidTorso">
		</div>
	</div>

```
```css
.legs {
	height: 200px;
	width: 240px;
	border: 2px solid white;
	display: flex;
	justify-content: center;
	align-items: center; 
	overflow: visible;
	border-top-left-radius: 6%;
	border-top-right-radius: 6%;
	border-bottom: 2px solid transparent; 
}
.droidTorso {
	background-color: var(--droidblue);
	height:200px;
	width: 200px;
	display: flex;
	justify-content: space-around;
	align-items: center; 
	overflow: hidden;
	flex-direction: column;
	border: 4px solid white;
	border-top: 2px solid transparent;
	border-bottom-left-radius: 20%;
	border-bottom-right-radius: 20%;

}

```

## Body Panels

![wire frame of R2D2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7wjpcxah5s2zfz66d0f.jpg)

The body panel is made from horizontal bars and a vertical box with ovals inside. Plus an empty spacer box to help position everything.

```HTML
	<div class="legs">
		<div class="droidTorso">
			<div class="box"></div>
			<div class="box"></div>
			<div class="openbox">
			   <div class="circle"></div>
			   <div class="circle"></div>	
			</div>
			<div class="emptybox"></div>
		</div>
	</div>
```

```css
.box {
	height: 10px;
	width: 50px;
	background-color: white;
}

.emptybox{
	background-color: transparent;
	height: 20px;
}  

.openbox{
	height: 60px;
	width: 40px;
	border:2px solid white;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	align-items: center;
}

.circle {
    height: 22px;
    width: 18px;
    border-radius: 33%;
    background-color: white;
}
```


## Feet
![wireframe of R2D2 slight blue tint to the background.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7t6b57umo7ieaoqhcuy.jpg)

 The feet are squares with a transparent border-top. The borders are slightly thicker than most of the borders in the design.

And that's how I made R2D2 using shapes and borders. 

```html
	<div class="feetRow">
		<div class="foot"></div>
		<div class="spacerFoot"></div>
		<div class="foot"></div>
		<div class="spacerFoot"></div>
		<div class="foot"></div>
	</div>

```

```css
.feetRow{
	height: 20px;
	width: 280px;
	
	display: flex;
	justify-content: space-around;
	align-items: center;

}

.foot{
	height: 10px;
	width: 40px;
	border: 4px solid white;
	border-top: 2px solid transparent;
}

.spacerFoot{
	height: 10px;
	width: 40px;
}

```

## Compare Background

Originally I didn't have a background for R2D2. But thought the smaller circle in his head blended in with the snow in the background. I added a background with a low opacity to help set it apart while still matching the figure on which the art is based.

What looks better with Droid background, top image, or not, bottom image?


![wireframe of R2D2 slight blue tint to the background.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7t6b57umo7ieaoqhcuy.jpg)


![Wireframe of R2D2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jiv4pg35laeqgo6jzd79.jpg)

## Star Wars Trivia ##

```javascript
"R2D2 We wish you a Merry Christmas!"
```

There was a Star Wars Christmas Album called "Christmas in the Stars". A song on it was "R2D2 we wish you a Merry Christmas" It's children singing to R2D2. It's the first professional recording of John Bongiovi. Know the name?

You may know him as John Bon Jovi of Bon Jovi. That's your music history lesson for the day.


```
-$JarvisScript git push
```

{% embed https://hachyderm.io/@jarvisscript %}