2017-07-20 08:38:55 -04:00
# TailwindCSS
A utility-first CSS framework for rapid UI development.
2017-10-13 15:09:15 -04:00
## Getting Started
1. Add the library to your project as a Git repo dependency:
```sh
# Using npm
npm install git+ssh://git@github .com:nothingworksinc/tailwindcss.git#master
# Using Yarn
yarn add git+ssh://git@github .com:nothingworksinc/tailwindcss.git#master
```
2017-10-13 19:44:19 -04:00
2. Create a Tailwind config file for your project by saving a copy of the default config file somewhere sensible, like `tailwind.js` in your project's root.
2017-10-13 15:09:15 -04:00
2017-10-13 19:44:19 -04:00
You can copy the default config file from here:
2017-10-13 15:09:15 -04:00
2017-10-13 19:44:19 -04:00
https://github.com/nothingworksinc/tailwindcss/blob/master/src/defaultConfig.js
2017-10-13 15:09:15 -04:00
2017-10-13 19:44:19 -04:00
3. Create a CSS (or Less, Sass, Stylus, whatever) file as your main stylesheet, structured like this:
2017-10-13 15:09:15 -04:00
```less
/**
* This injects Tailwind's base styles, which is a combination of
* Normalize.css and some additional base styles.
*
* You can see the styles here:
* https://github.com/nothingworksinc/tailwindcss/blob/master/css/preflight.css
*/
@tailwind reset;
/**
* Here you would import any custom component classes; stuff that you'd
* want loaded *before* the utilities so that the utilities can still
* override them.
*/
@import "my-components/foo";
@import "my-components/bar";
/**
* This injects all of Tailwind's utility classes, generated based on your
* config file.
*/
@tailwind utilities;
/**
* Here you would add any custom utilities you need that don't come out of the box with Tailwind.
*/
.bg-hero-image {
background-image: url('/some/image/file.png');
}
```
2017-10-13 19:44:19 -04:00
4. For simple projects or just taking Tailwind for a spin, use the `tailwind` CLI tool to process your CSS:
```sh
./node_modules/.bin/tailwind styles.css [-c ./custom-config.js] [-o ./output.css]
```
For most projects, you'll want to add Tailwind as a PostCSS plugin in your build chain, passing your config object as a parameter.
Here's an example using Laravel Mix:
```js
const mix = require('laravel-mix');
const tailwind = require('tailwindcss');
mix.less('resources/assets/less/app.less', 'public/css')
.options({
postCss: [
tailwind(require('./path/to/your/tailwind/config.js'))
]
});
```
2017-10-13 15:09:15 -04:00
## Style Reference
Until the real documentation is ready, you can reference this file to see which classes exist and what they do:
https://github.com/nothingworksinc/tailwindcss/blob/master/dist/tailwind.css
## Additional Features
2017-10-13 19:44:19 -04:00
### Using utilities as mixins
2017-10-13 15:09:15 -04:00
To use existing utility classes as mixins in your custom component classes, use the `@apply` custom at-rule:
```less
2017-10-13 19:44:19 -04:00
// Input
2017-10-13 15:09:15 -04:00
.btn-primary {
2017-10-13 19:44:19 -04:00
@apply .bg-blue;
@apply .px-4;
@apply .py-2;
2017-10-16 16:56:21 -04:00
@apply .text-white;
2017-10-13 19:44:19 -04:00
}
.btn-primary:hover {
@apply .bg-blue-dark;
}
2017-10-13 15:09:15 -04:00
2017-10-13 19:44:19 -04:00
// Output
.btn-primary {
background-color: #4aa2ea ;
padding-left: 1rem;
padding-right: 1rem;
padding-top: .5rem;
padding-bottom: .5rem;
color: #fff ;
}
.btn-primary:hover {
background-color: #3687c8 ;
2017-10-13 15:09:15 -04:00
}
```
2017-10-13 19:44:19 -04:00
2017-10-13 15:09:15 -04:00
### Referencing config values in your CSS
2017-10-13 19:44:19 -04:00
It's not always possible to build components purely out of existing utilities. If you need to reference any of your Tailwind config values directly, you can do so with the `tailwind(...)` helper function:
2017-10-13 15:09:15 -04:00
```less
.markdown pre {
border: 1px solid tailwind('borders.defaults.color');
border-left: 4px solid tailwind('borders.colors.dark');
}
```
### Creating responsive versions of your own utilities
You can generate responsive versions of your own utilities by wrapping their definitions in the `@responsive` at-rule:
```css
@responsive {
2017-10-13 19:44:19 -04:00
.bg-gradient-brand {
background-image: linear-gradient(blue, green);
}
2017-10-13 15:09:15 -04:00
}
```
This will generate these classes (assuming you haven't changed the default breakpoints):
```css
.bg-gradient-brand {
2017-10-13 19:44:19 -04:00
background-image: linear-gradient(blue, green);
2017-10-13 15:09:15 -04:00
}
@media (min-width: 576px) {
2017-10-13 19:44:19 -04:00
.sm\:bg-gradient-brand {
background-image: linear-gradient(blue, green);
}
2017-10-13 15:09:15 -04:00
}
@media (min-width: 768px) {
2017-10-13 19:44:19 -04:00
.md\:bg-gradient-brand {
background-image: linear-gradient(blue, green);
}
2017-10-13 15:09:15 -04:00
}
@media (min-width: 992px) {
2017-10-13 19:44:19 -04:00
.lg\:bg-gradient-brand {
background-image: linear-gradient(blue, green);
}
2017-10-13 15:09:15 -04:00
}
@media (min-width: 1200px) {
2017-10-13 19:44:19 -04:00
.xl\:bg-gradient-brand {
background-image: linear-gradient(blue, green);
}
2017-10-13 15:09:15 -04:00
}
```
### Media query shorthand
Say you have a `sm` breakpoint at 576px, and you need to write some custom CSS that references this breakpoint.
Instead of duplicating the values like this:
```css
@media (min-width: 576px) {
2017-10-13 19:44:19 -04:00
/* ... */
2017-10-13 15:09:15 -04:00
}
```
...you can use the `@screen` at-rule and pass the breakpoint name:
```css
@screen sm {
2017-10-13 19:44:19 -04:00
/* ... */
2017-10-13 15:09:15 -04:00
}
```