Table of Contents for
Mastering PostCSS for Web Design

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Mastering PostCSS for Web Design by Alex Libby Published by Packt Publishing, 2016
  1. Cover
  2. Table of Contents
  3. Mastering PostCSS for Web Design
  4. Mastering PostCSS for Web Design
  5. Credits
  6. About the Author
  7. About the Reviewer
  8. www.PacktPub.com
  9. Preface
  10. What you need for this book
  11. Who this book is for
  12. Conventions
  13. Reader feedback
  14. Customer support
  15. 1. Introducing PostCSS
  16. Introducing PostCSS
  17. Setting up a development environment
  18. Creating a simple example using PostCSS
  19. Linting code using plugins
  20. Exploring how PostCSS works
  21. Summary
  22. 2. Creating Variables and Mixins
  23. Creating a hover effect example
  24. Transitioning to using PostCSS
  25. Adding variable support to PostCSS
  26. Updating our hover effect demo
  27. Setting the order of plugins
  28. Creating mixins with PostCSS
  29. Looping content with PostCSS
  30. Summary
  31. 3. Nesting Rules
  32. Navigating through pages
  33. Transitioning to using PostCSS plugins
  34. Exploring the pitfalls of nesting
  35. Making the switch to BEM
  36. Exploring our changes in more detail
  37. Summary
  38. 4. Building Media Queries
  39. Exploring custom media queries in PostCSS
  40. Making images responsive
  41. Adding responsive text support
  42. Optimizing media queries
  43. Retrofitting support for older browsers
  44. Moving away from responsive design
  45. Taking things further with CSS4
  46. Summary
  47. 5. Managing Colors, Images, and Fonts
  48. Managing fonts with PostCSS
  49. Creating image sprites
  50. Working with SVG in PostCSS
  51. Adding support for WebP images
  52. Manipulating colors and color palettes
  53. Creating color functions with PostCSS
  54. Summary
  55. 6. Creating Grids
  56. Creating an example with Bourbon Neat
  57. Exploring the grid plugins in PostCSS
  58. Transitioning to using PostCSS-Neat
  59. Creating a site using Neat and PostCSS
  60. Adding responsive capabilities
  61. Summary
  62. 7. Animating Elements
  63. Moving away from jQuery
  64. Making use of pre-built libraries
  65. Switching to using SASS
  66. Making the switch to PostCSS
  67. Exploring plugin options within PostCSS
  68. Updating code to use PostCSS
  69. Creating a demo in PostCSS
  70. Optimizing our animations
  71. Using our own animation plugin
  72. Summary
  73. 8. Creating PostCSS Plugins
  74. Dissecting the architecture of a standard plugin
  75. Creating an transition plugin
  76. Building a custom font plugin
  77. Simplifying the development process
  78. Guidelines for plugin building
  79. Making the plugin available for use
  80. Summary
  81. 9. Working with Shortcuts, Fallbacks, and Packs
  82. Exploring plugin packs for PostCSS
  83. Adding shortcuts with Rucksack
  84. Linting and optimizing your code
  85. Providing fallback support
  86. Summary
  87. 10. Building a Custom Processor
  88. Exploring our processor
  89. Dissecting issues with our processor
  90. Optimizing the output
  91. Adding reload capabilities
  92. Extending our processor further
  93. Testing the final pre-processor
  94. Getting started with some hints and tips
  95. Introducing the CSStyle library
  96. Summary
  97. 11. Manipulating Custom Syntaxes
  98. Preparing our environment
  99. Implementing custom syntax plugins
  100. Parsing CSS
  101. Formatting the output with the API
  102. Highlighting our syntax code
  103. Summary
  104. 12. Mixing Preprocessors
  105. Exploring the conversion process
  106. Introducing the Pleeease library
  107. Compiling with other preprocessors
  108. Using the PreCSS library
  109. Converting a WordPress installation
  110. Setting up our environment
  111. Considering the conversion process
  112. Making changes to our code
  113. Compiling and testing the changes
  114. Summary
  115. 13. Troubleshooting PostCSS Issues
  116. Exploring some common issues
  117. Getting help from others
  118. Summary
  119. 14. Preparing for the Future
  120. Converting CSS4 styles for use
  121. Supporting future syntax with cssnext
  122. Creating plugins to provide extra CSS4 support
  123. Summary
  124. Index

Highlighting our syntax code

Throughout many of our demos, we've concentrated on using plugins, with minimal changes required to configure the code for use. There is nothing wrong with this, but as always, we can do better. How about installing support for highlighting?

This is an easy way to make it easier to read our code, indeed, we should have installed something like this a long time ago! That aside, it's easy enough to fix; support is available for a wide variety of editors. For the purposes of this chapter, I will assume you are using Sublime Text; this is an example of how it might look (the screenshot shows the Twilight Light theme in use):

Highlighting our syntax code

Let's dive in and take a look at how to get this set up, using Sublime Text's package manager.

Installing themes

Adding theme support is a cinch when using an editor such as Sublime Text. Let's work through the steps:

  1. We'll start by opening a command prompt session. Go ahead and add this command, then press Enter:
    cd %APPDATA%\Sublime Text 3\Packages\User
    
  2. Next, enter this command, then press Enter:
    git clone git://github.com/chriskempson/base16-textmate.git Base16
    
  3. Open Sublime Text. If all is well, we should see a new menu entry if we click on Preferences | Color Scheme | User:
    Installing themes

An easy change to make, but a useful one; nevertheless, it's only part of what we can do! To really go to town (figuratively speaking), we can apply similar styling to our CSS styles. This makes it easier to read if we want to document our styles online. After all, color is clearly easier to read than black and white! Let's take a moment to explore what is required to apply a color theme to our documented code.

Creating a HTML display theme

A part of developing code is the need to document it. This is not only for our sanity, but also for future changes, should someone else need to alter our code! Creating printed documentation is now old hat, a better method is to create it online, where we can easily update it without too much fuss. At the same time, we can add some color to it, to make it visually more appealing and provide a more consistent format to our efforts.

We could create this code manually, but that is a resource-heavy process that is prone to error! Instead, we can use the Midas library (available from http://midasjs.com) to automate the creation of the basis for our documentation, and we can style it using one of the base16 themes we covered in the previous exercise.

Let's make a start on installing that support:

  1. We'll start by firing up a NodeJS command prompt, then changing the working folder to our project area.
  2. At the prompt, enter this command, then press Enter:
    npm install midas --save-dev 
    
  3. Once it has finished installing, go ahead and extract the src folder and the gulpfile.js and package.json files from the T63 – incorporating midas folder, then save them to the root of our project area.
  4. Revert to the NodeJS command prompt, then enter gulp and press Enter.
  5. Gulp will go away and compile a HTML-based extract of our code as styles.html, which has been properly formatted with extra markup. The file will appear in the dest folder within our project area.

At this point, if we were to view the contents of that file, it will look very plain; this is easy to fix! To do this, we will use the Brewer theme by Timothée Poisot, available from https://github.com/chriskempson/base16-builder/blob/master/schemes/brewer.yml; there are a few steps involved to make this happen:

  1. Browse to https://github.com/ben-eb/midas/blob/master/templates/template-light.css, then save this as a CSS file within the dest folder of our project area.
  2. Open it in a text editor; it contains a series of placeholders for the base16 themes that are available for use. We would normally use Ruby to generate the CSS for one of these themes, but this isn't entirely necessary; instead, use your editor's search and replace to match up each placeholder with the appropriate color:
    Creating a HTML display theme
    Creating a HTML display theme
  3. Save the result; to make it work, we need to adjust the contents of the styles.html file to reference the new style sheet, so that it has the proper HTML structure. Once done, it will look something like this:
    Creating a HTML display theme

This looks far more appealing, I think you'll agree! Although it requires some work to create the initial theme, this will be a one-off process for each theme that you create. Any changes made to the CSS rules or declarations can be generated automatically, and the HTML result updates accordingly.