Adding Some Style
Creating a handful of components to render the data that loaded from a JSON file was covered in the previous post. It can feel a little defeating to just have a dump of content without any style to it. This step of the tutorial will cover implementing TailwindCSS to our project and adding some basic styling.

The fourth in a series of posts on 'HSMercs Helper From Scratch', a tutorial for recreating HSMercs Helper.
The native tutorial for installing Tailwind CSS with Vue 3 and Vite is straightforward and easy to follow. Most of what you'll see in this post is following the steps in that post.
PostCSS is a tool for transforming styles with JS plugins. These plugins can lint the CSS, support variables and mixins, transpile future CSS syntax, create inline images, and more. The Autoprefixer plugin parses CSS and adds vendor prefixes to CSS rules using values from Can I Use. Together, these provide the functionality that Tailwind uses to pump out the CSS we need it to.
The official tutorial now instructs you to run the command yarn tailwindcss init -p which creates a postcss.config.js file for PostCSS configuration and a tailwind.config.js file for Tailwind specific configuration.
postcss.config.js
This tells PostCSS to utilize the tailwindcss and autoprefixer plugins.
tailwind.config.js
Additional configuration is provided to TailwindCSS informing it to parse the root /index.html file and all .vue and .ts files anywhere under the src folder.
src/index.css
These three layers are where PostCSS and Autoprefixer inject the styles that Tailwind generates.
src/main.ts
The main script file loads the Tailwind generates CSS file into the full app. All of the magic happens behind the scenes, so we won't go into the details on how or why this happens. We're just happy it works.
src/App.vue
This applies a little styling to the header section of the app. Eventually, we will be putting navigation to different tools up there, so it is nice to give it some visual separation.
src/components/Mercenaries.vue
When there is a set of cards, and we don't particularly care how many are in a row, the best case is to use flex on the container, instructing the browser to place entries next to each other, and wrap (flex-wrap) onto the next line when the block element won't fit in the viewport. px-2 means to put a small padding on the left and right side of the container and gap-2 instructs flex to keep a small space between elements.

One of this first things I panicked on when I first installed Tailwind was that all of my text was suddenly the same size. What did I screw up?!
Well, fear not; this is intentional. The directive @tailwind base contains reset rules (called Preflight)that clear all of the browser defaults. Since each browser has slightly different default stylying, the first thing Tailwind does is strip it all out.
Style Some More Components
Most of the styling is going to be inside the Mercenary Card or one of its children. We can start by throwing around a couple classes and seeing what happens. Now is a good time to experiment and see what you like. This first pass doesn't involve adding any color or images, it is strictly to improve readability of the basic content.
src/components/MercenaryCard.vue
This right here is why I think CSS is so frickin' cool. We made a small adjustment to the CSS and BOOM, it looks so incredibly different. I get excited when I start seeing things really begin to take shape.
I hope you're getting excited, too.

Let's do a some touch-up here and there by going into some of the components and applying a little style.
src/components/AbilityStamp.vue
src/components/Attack.vue
src/components/Health.vue
src/components/ItemStamp.vue
src/components/Tribe.vue
Those little touches don't add much, but they set us to for the next stage in styling, which is to start having fun with dynamic colors and images based on properties of the mercenary.

Time For Some Images
All this grey and white and boxes is getting boring. The excitement is starting to wear off. Time to add some pictures into this. Head over to the repo for this project and download the images from the "/assets/" folder. It's safe to grab all of the images in that folder, but if you want to be selective, these are the ones we are going to work with first.
Assets Folder
├── assets
│ ├── alliance-watermark.png
│ ├── caster-attack.png
│ ├── caster-health.png
│ ├── epic.png
│ ├── fighter-attack.png
│ ├── fighter-health.png
│ ├── horder-watermark.png
│ ├── legendary.png
│ ├── neutral-attack.png
│ ├── neutral-health.png
│ ├── protector-attack.png
│ ├── protector-health.png
│ ├── rare.png
Be sure to place the assets folder at the root.
src/components/Attack.vue
src/components/Health.vue
If you've left the vite server running, your place should be autorefreshing with the new content when you save the Vue files. If not, go ahead and start it up, now. You can see how the affect of the role property plays out by dynamically setting the URL of the background image.
src/components/Rarity.vue
Tailwind's Preflight sets the img to display:block, so we need to set it back to inline for this instance. The max-h-6 is there to keep the image contained. We could also set an explicit height or width, but I prefer telling it the maximum allowed size and if the container shrinks, then the image will scale, too.

Tailwind Custom Colors
The next style we are going to implement is to color the border and the top bibbon of each card based on the class. Looking through Tailwind's default color palette, the colors red-800, green-800, and blue-800 seem to nicely fit with the Mercenaries color palette. However, instead of having to remember which color we picked for each class, and which shade is the right one, Tailwind allows us to create custom named colors.
tailwind.config.js
The Tailwind compiler (and the VSCode Intellisense) now know that "protector", "fighter", and "caster" are valid colors.
src/components/MercenaryCard.vue
How cool is that?! Using the role prop, Vue assigns the right border and background class to use. Tailwind knows to generate the appropriate CSS class to match the colors we want.
Tribe & Faction
There is a concept in Mercenaries PVE where some tribes are a part of the "Alliance" faction, others are in the "Horde", and the rest are neutral or without a faction. Instead of doing a long set of logic in the <template> block, we'll create a computed property that will evaluate the faction based on the mercenary's tribe.
src/components/Tribe.vue
The two arrays tell us which tribes are in which factions and the faction computed property does a quick look-up. We then utilize that value to drive the background-image style for the div.

