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

Optimizing media queries


Throughout this chapter, we've explored using PostCSS to compile our media queries; while there are plenty of options open to us in terms of what we create, we should be mindful of what we create, to ensure that we're not creating a monster that slows our site down!

PostCSS has a couple of plugins available to help us here. They are:

  • postcss-mq-keyframes: Available at https://github.com/TCotton/postcss-mq-keyframes), this is a simple plugin that moves all keyframes out of existing queries, to the bottom of a style sheet. This allows us to rationalize our keyframe rules—in the event that we have multiple media queries, we can apply the same rule to each of these media queries.

    For example, the highlighted code below would be moved out of the query, and become a rule in its own right:

    @media only screen and (min-width: 415px) {
      .pace {
        animation: pace-anim 5s;
      }
    
      @keyframes pace-anim {
        100% {
          opacity
    
  • css-mqpacker: Available at https://github.com/hail2u...