Getting Started With TailwindCSS

Tailwind is a utility-based css framework that inverts a lot of assumptions about how CSS classes should work, and forms a very viable alternative to something like Bootstrap. So let’s take a deeper look.

So What Is Tailwind?

How does it differ from Bootstrap?

Getting Started With Tailwind — The Wrong Way

mkdir tailwind-demo
cd tailwind-demo
touch index.html
code .
<!DOCTYPE html>
<html>
<head>
<title>Tailwind</title>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>

<h1>Tailwind Demo</h1>
<p>This is a tailwind demo.</p>
</body>
</html>

Let’s start with colour

<h1 class="text-blue-500">Tailwind Demo</h1>
<h1 class="text-blue-100">Tailwind Demo</h1>
<h1 class="text-blue-300">Tailwind Demo</h1>
<h1 class="text-blue-500">Tailwind Demo</h1>
<h1 class="text-blue-700">Tailwind Demo</h1>
<h1 class="text-blue-900">Tailwind Demo</h1>
<body class="bg-blue-100">
<h1 class="text-blue-500">Tailwind Demo</h1>
<p class="text-blue-900">This is a tailwind demo.</p>
</body>

Colours in Tailwind — They’re not all available

Margins and spacing

<body class="bg-blue-100 m-5">
<h1 class="text-blue-500 mb-3 text-xl">Tailwind Demo</h1>
<p class="text-blue-900">This is a tailwind demo.</p>
</body>

Putting the pieces together

<button class="py-2 px-4 rounded bg-green-600 text-white">
Success
</button>

Hover States

<button class="py-2 w-64 px-6 bg-indigo-600 text-indigo-100 
text-right font-hairline mr-5 border-indigo-800 border-r-8
hover:border-indigo-900">
Next section &raquo;
</button>

Installing Tailwind — The Hard Way

module.exports = {
plugins: [
require('tailwindcss')
]
}
@tailwind base;
@tailwind components;
@tailwind utilities;
<link rel="stylesheet" type="text/css" href="./style.css">
.button {
@apply py-2 w-64 px-6 bg-indigo-600 text-indigo-100 text-right font-hairline mt-10 border-indigo-800 border-r-8;
}
.button:hover {
@apply border-indigo-900;
}
.button {
@apply py-2 w-64 px-6 text-right font-hairline mt-10 border-r-8;
}
.button-indigo {
@apply bg-indigo-600 text-indigo-100 border-indigo-800;
}
.button-indigo:hover {
@apply border-indigo-900;
}
.button-green {
@apply bg-green-600 text-green-100 border-green-800;
}
.button-green:hover {
@apply border-green-900;
}

Weird Flex, But Ok

<div class="flex bg-orange-300 p-5">
<div class="w-1/5 bg-orange-700 text-orange-100 p-5">
LeftNav
</div>
<div class="flex-1 bg-orange-400 text-orange-800 p-5"> <h2 class="text-orange-700 text-lg mb-5">Tailwind Layout</h2> <p class="mb-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius natus iure suscipit repellendus quis nostrum, debitis repudiandae, laudantium fuga quas voluptatum illum, expedita eum sint ratione vero sunt! Id, sunt!</p> <p class="mb-3">Deserunt nihil quo numquam ut eaque voluptates rem, eveniet explicabo culpa fuga dolorum amet fugit eos! Enim sint dolorum inventore at perferendis.</p>

</div>
</div>

Responsive Design

- <div class="flex bg-orange-300 p-5">
- <div class="w-1/5 bg-orange-700 text-orange-100 p-5">
+ <div class="flex flex-col bg-orange-300 p-5">
+ <div class="flex-1 bg-orange-700 text-orange-100 p-5">
<div class="flex flex-col md:flex-row bg-orange-300 p-5">
<div class="flex-1 md:flex-none md:w-1/5 lg:w-1/6 xl:w-1/8
bg-orange-700 text-orange-100 p-5">

Some General Advice

Conclusion

--

--

Senior Web Developer based in Bangkok, Thailand. Javascript, Web and Blockchain Developer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matt Burgess

Senior Web Developer based in Bangkok, Thailand. Javascript, Web and Blockchain Developer.