TextAnnotation "I'll be talking about utility class styling and Tailwind CSS, which is a CSS framework that I've been using and I was an early adopter of."
TextAnnotation "Using inline styles, every value is a magic number."
TextAnnotation "With utilities, you're choosing styles from a predefined design system, which makes it much easier to build visually consistent UIs."
.. Switch to a standard page.
..raw:: pdf
PageBreak standardPage
- Text/border/background colours
- Font size/family/weight
- Alignment
- Padding/margin/negative margin
- Flexbox
- Positioning
- Lists
- z-index
- Opacity
..raw:: pdf
TextAnnotation "Some of the 'original' things that Tailwind would generate classes for."
..raw:: pdf
PageBreak
- Screenreader visibility
- Placeholder colour
- first-child, last-child, nth-child
- CSS Grid
- Transition
- Transform
- Spacing / Divide
- Focus ring
- Text clamping
..raw:: pdf
PageBreak titlePage
TextAnnotation "All generated from a single, customisable configuration file."
..class:: centredtitle
``block
inline
flex
grid``
..raw:: pdf
PageBreak
TextAnnotation "Instead of component-level classes like 'navbar' and 'card', we have classes like 'block', 'inline', 'flex' and 'grid' that describe what an element looks like and not what it is."
TextAnnotation ""
TextAnnotation "A class that toggles a single CSS property."
..class:: centredtitle
``text-sm
text-base
text-lg
text-xl
text-2xl``
..raw:: pdf
PageBreak
TextAnnotation "T-shirt size arguments."
..class:: centredtitle
``text-blue-50
text-blue-100
text-blue-200
text-blue-300
text-blue-400
text-blue-500``
..raw:: pdf
PageBreak imagePage
TextAnnotation "Arguments for text colour and shade."
..image:: images/screenshot-laravel-nova.png
:width:23cm
..raw:: pdf
PageBreak
..image:: images/screenshot-send-firefox.png
:width:23cm
..raw:: pdf
PageBreak
..image:: images/screenshot-rebuilding-bartik.png
:width:23cm
.. Switch to a title page.
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
How to use Tailwind
..raw:: pdf
PageBreak
..class:: centredtitle
Style elements by applying pre-existing classes directly in your HTML
..raw:: pdf
TextAnnotation "Instead of switching back and forth between HTML and CSS files, styling is done within the HTML markup by applying existing classes."
..raw:: pdf
PageBreak
..class:: centredtitle
Using utility classes to build custom designs without writing CSS
.. Switch to a standard page.
..raw:: pdf
PageBreak standardPage
Benefits
========
- You don't waste time and energy inventing class names.
- No switching between CSS and HTML files.
- Your CSS stops growing.
- Reusability.
- Making changes feels (and is) safer.
..raw:: pdf
TextAnnotation "No more adding silly class names like sidebar-inner-wrapper just to be able to style something, and no more agonizing over the perfect abstract name for something that's really just a flex container."
TextAnnotation "Using a traditional approach, your CSS files get bigger every time you add a new feature. With utilities, everything is reusable so you rarely need to write new CSS."
TextAnnotation ""
TextAnnotation "You can re-use components like a news card on events page as the classes aren't coupled to a specific component."
TextAnnotation ""
TextAnnotation "CSS is global and you never know what you're breaking when you make a change."
TextAnnotation "Classes in your HTML are local, so you can change them without worrying about something else breaking."
.. Switch to an image page.
..raw:: pdf
PageBreak imagePage
..image:: images/example/0.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/1.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/2.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/3.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/4.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/5.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/6.png
:width:18cm
..raw:: pdf
PageBreak
..image:: images/example/7.png
:width:18cm
.. Switch to a title page.
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
Installation and Usage
..raw:: pdf
PageBreak
..class:: centredtitle
``npm install --save-dev
tailwindcss``
..raw:: pdf
TextAnnotation "There is a CDN version available that provides everything but you can't customise it."
TextAnnotation "There's also the play.tailwindcss.com website that you can use."
TextAnnotation "Adds it as a dependency to your package.json file"
..raw:: pdf
PageBreak
..class:: centredtitle
``npx tailwind
--content index.html
--output build/tailwind.css``
..raw:: pdf
TextAnnotation "tailwind.config.js is optional, and an input file is optional."
.. Switch to a title page.
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
Interaction states
..raw:: pdf
PageBreak
..class:: centredtitle
``hover, focus, active, disabled, visited,
focus-within,
first-child, last-child``
..raw:: pdf
PageBreak
..class:: centredtitle
``[state][separator][class]``
..raw:: pdf
TextAnnotation "State = hover, focus, group focus, focus within."
TextAnnotation "Separator = configurable"
TextAnnotation "Colon by default"
TextAnnotation "Class = the same utility class that you would have used normally"
TextAnnotation "Move the duplicate markup into a partial, so there's only one version. Pass data in."
Includes
========
..code-block:: html
:linenos:
<h2>Adults</h2>
<ClassList classes={classes} type="kids" />
<h2>Kids</h2>
<ClassList classes={classes} type="adults" />
Extracting CSS components
=========================
..code-block:: css
:linenos:
:include:code/css-apply-before.txt
Extracting CSS components
=========================
..code-block:: css
:linenos:
:include:code/css-apply-after.txt
.. Switch to a title page.
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
Keeping Things Small: Controlling the file size
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
Just in Time (JIT mode)
..raw:: pdf
TextAnnotation "Since the JIT mode was added and changed to be the default option, Tailwind only generates the classes that it needs to - i.e. only the classes in your HTML."
.. Switch to a title page.
..raw:: pdf
PageBreak standardPage
Content
=======
Tell Tailwind where it should look for utility classes.
|
..code-block:: javascript
:linenos:
:include:code/tailwind-config-content.js
..raw:: pdf
TextAnnotation "Tailwind will scan the files within the content array and "
.. Switch to a title page.
..raw:: pdf
PageBreak titlePage
..class:: centredtitle
Customising Tailwind
..raw:: pdf
PageBreak
..class:: centredtitle
``npx tailwind init``
.. Switch to a standard page.
..raw:: pdf
PageBreak standardPage
tailwind.config.js
==================
..code-block:: javascript
:include:code/tailwind-basic-config.txt
:linenos:
Overriding configuration
========================
..code-block:: javascript
:include:code/override-colours.txt
:linenos:
:hl_lines:5 6 7
..raw:: pdf
TextAnnotation "Overrides all colours. Great for when you've been given a colour pallete for a project from a Designer."