From 0af4718fb8e5de3fe2d6082dfc31beca99cc704e Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Tue, 31 Oct 2017 08:49:34 -0400 Subject: [PATCH] Add example of renaming screen sizes --- docs/source/docs/responsive-design.blade.md | 47 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/source/docs/responsive-design.blade.md b/docs/source/docs/responsive-design.blade.md index 42e0a4aed..d6aa0acba 100644 --- a/docs/source/docs/responsive-design.blade.md +++ b/docs/source/docs/responsive-design.blade.md @@ -5,7 +5,7 @@ title: "Responsive Design" # Responsive Design -Tailwind allows you to build responsive designs in the same way you build the rest of your design—using utility classes. Every utility in Tailwind is also available in screen-size specific variations. For example, the `.font-bold` utility can be used on small screen sizes using the `.sm:font-bold` class, on medium screen sizes using the `.md:font-bold` class, on large screen sizes using the `.lg:font-bold` class and on extra large screen sizes using the `.xl:font-bold` class. +Tailwind allows you to build responsive designs in the same way you build the rest of your design — using utility classes. Every utility in Tailwind is also available in screen-size specific variations. For example, the `.font-bold` utility can be used on small screen sizes using the `.sm:font-bold` class, on medium screen sizes using the `.md:font-bold` class, on large screen sizes using the `.lg:font-bold` class and on extra large screen sizes using the `.xl:font-bold` class. This is done using predefined screen sizes (media query breakpoints), each of which are given a unique name like `sm`, `md`, `lg` and `xl`. By default Tailwind takes a "mobile first" approach, where each screen size represents a minimum viewport width. Any classes you apply at smaller screen sizes are also applied to larger sizes, unless of course you override them, which is the whole point! This approach, while simple, is actually very powerful and can be used to build complex, beautiful, responsive designs. @@ -46,19 +46,62 @@ This is done using predefined screen sizes (media query breakpoints), each of wh ## Customizing screens -You define your project's screen sizes in your Tailwind config under the `screens` key. Screens in Tailwind are essentially CSS media queries. If you provide a single value for a screen, Tailwind will treat this as the minimum screen size value for that screen breakpoint. Here are the default screen sizes: +You define your project's screen sizes in your Tailwind config under the `screens` key. Screens in Tailwind are essentially CSS media queries. If you provide a single value for a screen, Tailwind will treat this as the minimum screen size value for that screen breakpoint. + +Here are the default screen sizes: ```js screens: { 'sm': '576px', + // => @media (min-width: 576px) { ... } + 'md': '768px', + // => @media (min-width: 768px) { ... } + 'lg': '992px', + // => @media (min-width: 992px) { ... } + 'xl': '1200px', + // => @media (min-width: 1200px) { ... } }, ``` Feel free to have as few or as many screens as you want, naming them in whatever way you'd prefer for your project. +For example, you could use device names instead of sizes: + +```js +screens: { + 'tablet': '576px', + // => @media (min-width: 576px) { ... } + + 'laptop': '992px', + // => @media (min-width: 992px) { ... } + + 'desktop': '1200px', + // => @media (min-width: 1200px) { ... } +}, +``` + +These screen names will be reflected in your utilities, so your `.bg-red` utilities would now look like this: + +```css +.bg-red { background-color: config('colors.red'); } + +@media (min-width: 576px) { + .tablet\:bg-red { background-color: config('colors.red'); } +} + +@media (min-width: 992px) { + .laptop\:bg-red { background-color: config('colors.red'); } +} + +@media (min-width: 1200px) { + .desktop\:bg-red { background-color: config('colors.red'); } +} +``` + + ## Advanced screens Tailwind also allows for more complex screen definitions, which can be useful in certain situations. For example, if you wanted to define both the minimum and maximum size for your screens, you could do that like this: