If you spend any time working with CSS, then it is likely you will come across instances where you wished there was a quicker way to add a particular block of code to your page, apply vendor prefixes, or perhaps set a predefined border to an element on the page.
We can easily achieve this by using one or more of the many shortcuts, fallbacks, or pack plugins available for use with PostCSS. In this chapter, we'll explore some common scenarios where plugins are required, before learning how to create them in the next chapter. We will cover a number of topics throughout this chapter, which will include the following:
Let's get cracking!
Building a web-based application or site can be a lengthy process—there are so many elements to consider, and it takes time to create content that is engaging and informative.
Naturally, a smart designer or developer will always look for a shortcut to save time—after all, why take an hour to do something, if a shortcut will take half the time? The great thing about PostCSS is that it has a good selection of shortcut plugins that we can use; these include plugins such as the examples:
postcss-focus: This plugin is available at https://github.com/postcss/postcss-focus, this simple plugin adds a :focus pseudo-selector to any :hover attribute encountered in a style rule.postcss-border: If specified in a shorthand version, this plugin will add a border-width attribute to an existing border: attribute. The plugin source is available from https://github.com/andrepolischuk/postcss-border.postcss-short-data: This plugin is available at https://github.com/jonathantneal/postcss-short-data, this interesting plugin allows us to write shorthand data attribute selectors, akin to pseudo-selectors, which are compiled into data- attributes.We've already incorporated or talked about a number of the shortcut plugins that are available within PostCSS—these include postcss-responsive-type which we used to build a responsive page earlier in the book, easings, and of course, postcss-transform-shortcut from Chapter 7, Animating Content.
There are a lot more plugins available for use. Throughout the course of this chapter, we're going to explore some of the shortcut plugins available, plus some of the packs that we can use to supplement functionality within our preprocessor. A good place to start is the selection of plugin packs available for use within PostCSS—let's take a moment to explore these in more detail.