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

Retrofitting support for older browsers


For those of you who still have to support older browsers, such as IE6-8, then PostCSS can help—we can use the postcss-mqwidth-to-class plugin to generate hardcoded class rules, based on the media queries we specify, such as this example:

@media (min-width: 1024px) and (max-width: 1298px) {
  .bar { float: left; }
}

If we compile it using this plugin, it will produce this result:

.min-width-1024px.max-width-1298px .bar { float: left; }

Anyone spot the danger here? The code may be technically correct, but it suffers from some limitations which make it less attractive: a risk of high levels of CSS specificity, media types are ignored (such as screen or print); and JavaScript may be required if adding classes to the <body> or <html> tags.

Ultimately it is down to us to decide what we need to use, but we should always be mindful that our code doesn't introduce new issues if we have to support older browsers! In this instance, a better alternative...