Book Image

Mastering PostCSS for Web Design

By : Alex Libby
Book Image

Mastering PostCSS for Web Design

By: Alex Libby

Overview of this book

PostCSS is a tool that has quickly emerged as the future of existing preprocessors such as SASS and Less, mainly because of its power, speed, and ease of use. This comprehensive guide offers in-depth guidance on incorporating cutting-edge styles into your web page and at the same time maintaining the performance and maintainability of your code. The book will show how you can take advantage of PostCSS to simplify the entire process of stylesheet authoring. It covers various techniques to add dynamic and modern styling features to your web pages. As the book progresses, you will learn how to make CSS code more maintainable by taking advantage of the modular architecture of PostCSS. By the end of this book, you would have mastered the art of adding modern CSS effects to web pages by authoring high performing, maintainable stylesheets.
Table of Contents (21 chapters)
Mastering PostCSS for Web Design
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Exploring custom media queries in PostCSS


Making the switch to using PostCSS is a cinch, we can use the postcss-custom-media plugin for this purpose, available at https://github.com/postcss/postcss-custom-media.

The plugin is easy to install, it follows the same principles as all of the other plugins we've covered, so without further ado, let's get that out of the way now:

  1. Fire up a Node.js command prompt, then navigate to the working directory.

  2. At the prompt, enter this command, then press Enter:

    npm install --save-dev postcss-custom-media
    
  3. Keep the command prompt open for now, we will use it in the next few steps.

    With the plugin installed, we can now use it, before we get stuck into converting our previous demo, let's work through a simple example, so you can see it in action:

  4. In a new file, add the following code, saving it as style.css within the src folder at the root of our project area:

    @custom-media --apple-watch (max-device-width: 42mm) and (min-device-width: 38mm);
    
    @media (--apple-watch...