autoscale: true
build-lists: true
theme: Fira, 1
[.hide-footer]
# [fit] _**Taking Flight with** Tailwind CSS_
---
[.build-lists: false]
- Full Stack Web Developer
- Acquia certified Drupal specialist
- @opdavies
- oliverdavies.uk
---
> A Utility-First CSS Framework for Rapid UI Development
^ What is Tailwind?
---
[.build-lists: false]
- Utility CSS class generator
- PostCSS
- Configurable
- Some preprocessor features
- Can be used in addition to preprocessors
- Open source
^ Works with plain CSS or any preprocessor
Can be configured to enable/disable modules, configure colours etc.
Can use features like variables if using plain CSS.
---
```css
.title {
background-color: #3490DC;
color: #FFF;
display: block;
font-size: 1.5rem;
padding: 2rem;
}
```
---
```css
.text-2xl {
font-size: 1.5rem;
}
.bg-blue {
background-color: #3490DC;
}
.text-white {
color: #FFF;
}
```
---
```html
```
---
## __Extracting Components__
---
```twig
{% for item in items %}
{{ item.title }}
{% endfor %}
```
---
```html
Click me!
Click me too!
```
---
```less
// main.less
.button {
.inline-block;
.rounded;
.text-sm;
.py-2;
.px-3;
.text-white;
}
```
---
```css
# main.css
.button {
@apply .inline-block;
@apply .rounded;
@apply .text-sm;
@apply .py-2;
@apply .px-3;
@apply .text-white;
}
```
---
```html
Click me!
Click me too!
```
---
```less
// table.less
.table-responsive {
@apply .mb-4 .border .w-full;
overflow-x: auto;
overflow-y: hidden;
}
.table-responsive table {
@apply .mb-0 .border-0 .whitespace-no-wrap;
}
.table {
@apply .w-full .table-collapse;
}
.table tr:nth-child(odd) {
@apply .bg-grey-lightest;
}
.table tr th {
@apply .text-left .p-3 .bg-white;
}
.table td {
@apply .px-3 .py-3 .border-t;
}
```
---
## Advantages
- Quick to prototype and make changes
- Write less CSS
- More consistency
- Easy to customise, promote to components
- Mix and match with normal CSS
^ Do more with browser dev tools
Only picking from pre-defined colours, widths. No magic numbers.
Less ramp-up time as using the same framework on different sites.
Same classes, but no visual similarities like with other frameworks like Bootstrap
---
## Disadvantages
- Extra build tools and steps
- Lots of classes in markup
- Large file size by default
^ - Need a build tool (Gulp, Grunt, Webpack) to build CSS
---
## For Drupal
- Add a prefix to avoid clashing
- Enable `important` setting to override existing styles
- Add classes in templates where possible
- Use `@apply` to limit the number of templates, to avoid adding classes in PHP code or config (e.g. Views), to style hard-to-reach elements
---
## Resources
- tailwindcss.com
- tailwindcomponents.com
- github.com/merchedhq/awesome-tailwindcss
- youtube.com/adamwathan
- github.com/opdavies/oliverdavies.uk
- github.com/phpsw/phpsw-ng
---
## __Thank you__
### @opdavies