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

Creating a hover effect example

If you've seen any of my previous books, then you will see I have a thing about flowers, and in particular orchids; indeed, the cover on my first book was that of a phalaenopsis, or moth orchid! We'll use a couple of images of orchids as the basis for our next demo, as shown in the screenshot over the page, where it shows our desired effect in motion for the top image.

Tip

If you prefer using Less, then please skip to the end of this demo for an example using Less CSS.

For this demo, we will need a copy of the tutorial1A folder from the code download that accompanies this book; make sure you dig that out before continuing:

  1. Open up a copy of style.scss from the src folder within tutorial1A; let's take a look at its contents.
  2. At the top of the file, we have a small handful of variables. These define some of the colors used within the code, and set the $fullsize variable to 100%:
    Creating a hover effect example

    The sharp-eyed among you will spot that not all colors have been given a value; the reason for this will become clearer later in this chapter.

  3. Next up comes an example of a simple mixin, which converts pixel values to their rem unit equivalents, using 16px as the base equivalent for 1rem unit:
    Creating a hover effect example
  4. To complete the exercise, we need to download a font. The demo uses the Source Sans Pro font available at http://www.fontsquirrel.com/fonts/source-sans-pro. Go ahead and download it; you will need to use the Generator option available from the black menu to produce a version that can be used online (it creates the CSS we've used in our demo).
  5. At this point, go ahead and drop a copy of the style.scss file from the tutorial1A folder into the src folder in our project area.
  6. We also need the img folder and the index.html file—go ahead and copy both across to the root of our project area.
  7. Fire up a Node.js command prompt window, then enter this at the prompt and press Enter:
    gulp
    
  8. If all is well, we should see compressed CSS files and source maps appear in the dest folder in our project area—copy the maps folder and style.min.css into the css folder of tutorial1A.
  9. Go ahead and preview the results in a browser. If all is well, we should see two orchid images appear on screen; if you hover over either one, you will see it fly to the left or right, to reveal an information box with information about the orchid:
    Creating a hover effect example

Interesting effect, huh? It's a simple animation that uses scale() to shrink the image to 0.5 (or 50%) of its size and slides it to the right, before sliding in the infobox immediately behind it. Take the mouse off the image and the reverse happens—it's the sample principle for the second image—but in reverse; the code sets an ltr and rtl class to determine which direction the image should move in the demo.

Using Less CSS as an alternative

A copy of this demo using the equivalent code from the Less CSS pre-processor is available in the code download that accompanies this book. It's in the Tutorial1B folder if your preference is to use the Less CSS pre-processor; you will need to install the gulp-less plugin from https://github.com/plus3network/gulp-less, using NodeJS (in the same manner as other plugins that we've installed). An updated copy of the Gulp task file is also included in this folder, along with completed versions of the CSS code.