Shared posts

13 Oct 15:00

Using PostCSS for Cross Browser Compatibility

by Kezz Bracey

In the last tutorial we wrapped up our “Quick Start” section of this series, and we’re now ready to move onto using PostCSS to generate stylesheets, employing different kinds of plugins for various purposes.

In this tutorial we’re going to use PostCSS to create a stylesheet designed for cross browser compatibility. We will:

  • Have vendor prefixes automatically added in
  • Add a series of fallbacks for Internet Explorer versions 8, 9 and 10
  • Add fallbacks for the not yet widely supported will-change property

Let’s begin!

Setup Your Project

The first thing you’ll need to do is setup your project to use either Gulp or Grunt, depending on your preference. If you don’t already have a preference for one or the other I recommend using Gulp as you’ll need less code to achieve the same ends.

You can read about how to setup Gulp or Grunt projects for PostCSS in the previous tutorials

respectively.

If you don't want to manually setup your project from scratch though, you can download the source files attached to this tutorial, and extract either the provided Gulp or Grunt starter project into an empty project folder. 

Then, with a terminal or command prompt pointed at the folder, run the command npm install.

Install Plugins

Now that you have your empty Gulp or Grunt + PostCSS project ready, we need to install the plugins you’ll be using in this tutorial.

We’re going to be installing quite a few plugins, so instead of installing them one at a time as we did in the “Quickstart Guides” for Gulp and Grunt, we’ll install them all at once with a single command.

Whether you’re using Gulp or Grunt, run the following command inside your project folder to install the plugins we’ll be using:

npm install autoprefixer postcss-color-rgba-fallback postcss-opacity postcss-pseudoelements postcss-vmin pixrem postcss-will-change --save-dev

Now the plugins are installed, let’s go ahead and load them into your project.

Load Plugins via Gulp

If you’re using Gulp, add these variables under the variables already in the file:

var autoprefixer = require('autoprefixer');
var color_rgba_fallback = require('postcss-color-rgba-fallback');
var opacity = require('postcss-opacity');
var pseudoelements = require('postcss-pseudoelements');
var vmin = require('postcss-vmin');
var pixrem = require('pixrem');
var will_change = require('postcss-will-change');

Now add each of those new variable names into your processors array:

    var processors = [
		will_change,
		autoprefixer,
		color_rgba_fallback,
		opacity,
		pseudoelements,
		vmin,
		pixrem
	];

Do a quick test that everything is working by running the command gulp css then checking that a new “style.css” file has appeared in your project's "dest" folder.

Load Plugins via Grunt

If you’re using Grunt, update the processors object, which is nested under the options object, to the following:

        processors: [
          require('postcss-will-change')(),
          require('autoprefixer')(),
          require('postcss-color-rgba-fallback')(),
          require('postcss-opacity')(),
          require('postcss-pseudoelements')(),
          require('postcss-vmin')(),
          require('pixrem')()
        ]

Do a quick test compile by running the command grunt postcss then checking that your project’s “dest” folder now contains a new “style.css” file.

You now have all the plugins installed that are required for this tutorial, and you’re ready to move onto seeing how to use them to enhance your stylesheets’ cross browser compatibility.

Automatically Add Vendor Prefixing

Some of the measures for cross browser compatibility we’ll be covering will only be necessary for specific use cases. Automated vendor prefixing, on the other hand, is something I would suggest should be done with every project, via the Autoprefixer plugin created by Andrey Sitnik.

It can be difficult to keep tabs on which properties require which vendor prefixes at any given time, and by using Autoprefixer you don’t have to. Use Autoprefixer as part of every project and it will check your code against the data from CanIUse.com, then add vendor prefixes as necessary without you having to think about it.

Let’s do a little test to see Autoprefixer in action. Add the following animation and flexbox code to your project’s “src/style.css” file:

@keyframes animationExample {
    from {
		width: 0;
	}
	to {
		width: 100%;
	}
}

.animateThis {
	animation: animationExample 2s;
	display: flex;
}

Run gulp css or grunt postcss to compile your file, and your “dest/style.css” should now contain this vendor prefixed code:

@-webkit-keyframes animationExample {
    from {
		width: 0;
	}
	to {
		width: 100%;
	}
}

@keyframes animationExample {
	from {
		width: 0;
	}
	to {
		width: 100%;
	}
}

.animateThis {
	-webkit-animation: animationExample 2s;
	        animation: animationExample 2s;
	display: -webkit-box;
	display: -webkit-flex;
	display: -ms-flexbox;
	display: flex;
}

As you can see, vendor prefixes have been automatically added in, as dictated by the data provided from CanIUse.com on animation and flexbox.

Specifying Browser Support Levels

Autoprefixer uses Browserlist to determine which browser versions it will add support for. Under default settings it will apply vendor prefixes as required for:

  • > 1%: browsers used by more than one percent of people globally
  • last 2 versions: the last two versions of every browser tracked by CanIUse.com
  • Firefox ESR: the latest Firefox version
  • Opera 12.1: Opera version 12.1

The example we ran through above was compiled under Autoprefixer’s default settings. This meant support for IE10 and Safari 8 was included, so the -ms- and -webkit- prefixes they require for animation and flexbox were automatically inserted.

However, IE11 and Safari 9 don’t require these prefixes, so if you were to set your browserlist configuration to support only IE11+ and Safari 9+ these prefixes would no longer be added.

Try this out by passing a browsers setting through to Autoprefixer in your Gulpfile or Gruntfile like so:

// In the Gulpfile 'processors' array:
autoprefixer({browsers:'safari >= 9, ie >= 11'}),

// In the Gruntfile 'processors' array:
require('autoprefixer')({ browsers: ['safari >= 9, ie >= 11'] }),

Now if you recompile your CSS you’ll see there is no difference between your original and compiled code. This is because, with no support requested for Safari 8 or IE10, no vendor prefixes have been added in to suit them.

Related Links:

Add Fallback for “will-change” Property

The will-change property is used to let a browser know ahead of time that certain elements of your design are going to be animated. This allows the browser to optimize the rendering process and prevent delays and flickers. However, at present this property is not supported by IE / Edge, Safari or Opera Mini.

The postcss-will-change plugin, also created by Andrey Sitnik, adds a fallback that will help these browsers do a better job of rendering, even if not with the efficiency they could if they supported will-change. It does so by adding the backface-visibility property, which triggers the creation of a compositor layer that will be handled by the GPU.

For example, add this code to your “src/style.css” file:

.thisWillChange {
    will-change: transform;
}

Compile your stylesheet and you should see the fallback appear in your “dest/style.css” file:

.thisWillChange {
    backface-visibility: hidden;
    will-change: transform;
}

Note: this plugin should be loaded before Autoprefixer in your Gulpfile/Gruntfile. This is to allow Autoprefixer to add vendor prefixes to the backface-visibility property, like so:

/* Fallback with vendor prefixes */
.thisWillChange {
    -webkit-backface-visibility: hidden;
	        backface-visibility: hidden;
	will-change: transform;
}

Related Links

Add Fallbacks for Old IE Issues

Thanks to improved browser versions from Microsoft, and major groups leading the way in dropping support for old IE, we’re gradually edging closer to not having to constantly consider fallbacks and workarounds for problematic legacy browsers. Microsoft itself will be dropping support for IE8 in 2016. Bootstrap 4 alpha was recently released and it has also dropped support for IE8. Google stopped supporting IE8 in 2012 and dropped IE9 support in 2013.

All that said, at the end of the day every project has to be assessed on a case by case basis, and if you’re targeting a demographic that has high usage rates of legacy browsers, you may have no choice but to do your best to support them. If that’s the case, the following plugins can help you make that process a little less painful.

Create rgba() Color Fallbacks

IE8 has no support for rgba() colors, so the postcss-color-rgba-fallback plugin by Guillaume Demesy adds a flat hexadecimal color as a fallback.

For example, add this code to your “src/style.css” file:

.rgbaFallback {
    background: rgba(0,0,0,0.5);
}

Compile and you should see the hexcode fall back added to your “dest/style.css” file:

.rgbaFallback {
    background: #000000;
    background: rgba(0,0,0,0.5);
}

Related Links

Create opacity Fallbacks

IE8 can’t handle the opacity property, so the postcss-opacity plugin by Vincent De Oliveira adds an IE specific filter to achieve the same effect.

Add this code to your source stylesheet:

.opacityFallback {
    opacity: 0.5;
}

After compilation you should see the appropriate -ms-filter fallback added:

.opacityFallback {
    opacity: 0.5;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}

Related Links

Convert :: into : on Pseudo-elements

It’s considered best practice when generating pseudo-elements such as .element::before to use a double colon notation ::. This is to help distinguish them from pseudo-classes such as .element:hover which should use a single colon notation :.

However, IE8 doesn’t support the double colon notation :: to create pseudo-elements, it only supports a single colon :. By using the postcss-pseudoelements plugin by Sven Tschui you can code according to best practices, and have the notation changed automatically.

Add the following double :: notation code:

.pseudo-element::before {
    content: '';
}

Compile your file and you should see it has been reduced to the single : notation:

.pseudo-element:before {
    content: '';
}

By coding to best practices and using this plugin, once IE8 is completely retired you can just reprocess your CSS without the plugin and have proper syntax in place.

Related Links

Add vm Fallback for vmin

In IE9 the viewport relative unit vmin is not supported, but instead uses the equivalent unit vm. If you’re catering to IE9, the postcss-vmin plugin by Vincent De Oliveira will add vm units as a fallback.

Add this code to your “src/style.css” file:

.vmFallback {
    width: 50vmin;
}

Recompile, and the resulting code should have the vm unit fallback added in:

.vmFallback {
    width: 50vm;
    width: 50vmin;
}

Related Links

Add px Fallback for rem Units

IE8 doesn’t support rem units at all, and in both IE9 and IE10 they are unsupported in psuedo-elements and font shorthand declaration. With the node-pixrem plugin by Vincent De Oliveira and Rob Wierzbowski you can have px based fallbacks added automatically wherever you use rem units.

Add this code to your source stylesheet:

.remFallback {
    height: 10rem;
	font: 2rem Arial;
}

.remFallback::before {
	content: '';
	line-height: 1rem;
}

Recompile and you should see all the appropriate px fallbacks added:

.remFallback {
    height: 160px;
    height: 10rem;
	font: 32px Arial;
	font: 2rem Arial;
}

.remFallback:before {
	content: '';
	line-height: 16px;
	line-height: 1rem;
}

Related Links

Let’s Recap

To sum up what we’ve covered in the above:

In the Next Tutorial

Coming up next in our PostCSS Deep Dive series is a tutorial on how to use plugins to minify and optimize your CSS. We’ll cover inlining @import files, combining media queries, stripping white space and several more methods to make your stylesheets as streamlined as possible. See you there!

16 Sep 09:13

When did you give up?

by Seth Godin

The bureaucracy is no longer your enemy. The bureaucracy is you.

And it's easy to blame your boss, or the dolt who set up all these systems, or the one who depersonalizes everything. The policies and the oversight and the structure almost force you to merely show up. And to leave as early as you can.

But the thing is, the next job, like the last one, is going to be like this. If this is the job you're seeking, if this is the level of responsibility you take, perhaps it's not just your boss.

How long ago did you decide to settle for this? How long ago did you start building the cocoon that insulates you from the work you do all day?

Years ago, the spark was still there. The dreams. And most of all, the willingness to take it personally.

You can take it personally again. 

       
29 Jul 09:00

Gardens, not buildings

by Seth Godin

Great projects start out feeling like buildings. There are architects, materials, staff, rigid timelines, permits, engineers, a structure.

It works or it doesn't.

Build something that doesn't fall down. On time.

But in fact, great projects, like great careers and relationships that last, are gardens. They are tended, they shift, they grow. They endure over time, gaining a personality and reflecting their environment. When something dies or fades away, we prune, replant and grow again.

Perfection and polish aren't nearly as important as good light, good drainage and a passionate gardener.

By all means, build. But don't finish. Don't walk away.

Here we grow.

       
21 Jul 20:27

VerbalExpressions : JavaScript Regular expressions made easy

20 Jan 18:33

Front-end performance for web designers and front-end developers

A comprehensive primer on front-end performance for designers and front-end developers
15 Jul 22:00

123. ERICA GOLDSON: Graduation speech

by Gav

123. ERICA GOLDSON: Graduation speech

This is part of the speech Erica Goldson, the 2010 Valedictorian of Coxsackie-Athens High School, gave at her graduation ceremony.
The speech was uploaded on YouTube, went viral and Erica became known as the ‘Valedictorian who spoke out against schooling’. You can watch the entire speech and read the transcript here.

Erica’s speech really struck a nerve with me because I was totally like her when I was in school. I always did what I was told, didn’t ask too many questions, mindlessly memorised then regurgitated facts and figures. I remember I would write out an entire essay for homework, memorise the whole thing, then write it down verbatim on test day … and then promptly forget it and move on to the next assignment. I graduated near the top of my class, but on hindsight, I’m not sure I learnt much. The pattern continued as I went on to university, even though I never really wanted to be a graphic designer. But the piece of paper I received at the end did help me land a job, so it was all worth it in the end right? Maybe if I had heard this speech back in high school, I would have realised I was stuck in the system and gone down a different path.

One positive thing I do remember about school is that I doodled on EVERYTHING – my textbooks, files, folders, desk, arms, legs,
pencil case and all of my friend’s stuff as well (mainly pictures of Batman, sometimes Wolverine, the occasional Ninja Turtle). If only I spent MORE time doodling and less time being a robot.

Related comics: 11 Ways to be Average. The Road Not Taken.

- Thanks to Jesse for submitting this.
- Check out this in-depth article about myself and the growth of Zen Pencils by viral media expert Jonathan Goodman. It’s especially relevant if you’re interested in starting your own website, blog or webcomic.

24 Jun 13:16

Smarten up your data with Eclipse BIRT

by Jason Weathersby

From March's JAX Magazine, former Eclipse BIRT evangelist Jason Weathersby guides us through some of the major features within the business intelligence reporting toolkit

Eclipse’s Business Intelligence and Reporting Tools (BIRT) is an open source project based on the Eclipse IDE and is used to build and deploy reports in a Java/J2EE environment. As of this writing, the current version is BIRT 4.2 - the ninth major release - and the BIRT project continues to be very popular with more than twelve million downloads. BIRT contains many features and supports both OSGi and POJO runtimes, allowing developers to integrate with many types of applications.

This article series will serve as an introduction to the BIRT project, with a focus on the BIRT designer, highlighting some of the major features used to build and customize reports and libraries. General details about the BIRT pipeline, event handling and expressions will also be explained. Deployment in general will not be discussed in this article, but information about the AJAX based Web Viewer, the Report Engine API, and the BIRT tag libraries can be found on the Eclipse website. Figure 1 shows just a few of the things you can do in Eclipse BIRT.

Figure 1: BIRT Collage

Why BIRT?

Most IT software as well as many other applications focus on processes to collect, analyze and present data. The field of Business Intelligence (BI) is the use of this data by IT professionals and business analysts to improve business decision-making. 

In the past, BI data was typically presented in the form of page-based printed reports. Even today, many reporting systems still use this metaphor at the core of their architecture which, let’s face it, does not match well with the web-focused interactive experience we use to make decisions today. In fact this page-centric view limits the ability of a designer from easily integrating such systems into Rich Client Platforms (RCP) and often leads to reports being custom built from scratch.

BIRT was created from the ground up to address the need for a reporting system with the web interface central to its architectural design, built with RCP technology in mind and  based on the industry-leading open source Eclipse platform. As you'll see, BIRT's modern design, along with the highly interactive and extensible BIRT Designer, allows the implementation of highly visual and dynamic rich client applications.

Before discussing the BIRT Report Designer, an overview of the BIRT Pipeline, event handling and the BIRT Expression Builder is in order. These three areas affect virtually every aspect of the BIRT design experience.

Pipeline

BIRT Report designs are XML documents that are created in the report design tool. These designs can either be created from a report template or started from scratch with a blank design.

Templates are often used to set up header and footers and offer a starting point for common report types. Reports can optionally reference report libraries, which are XML documents that contain portions of a report. For example, if your company header is published to a report library, this header can then be used in all of your reports – and if the header is changed at a later date, the reports that reference this library will automatically show the changes the next time the report is executed. Most BIRT report items can be placed in a library by simply right clicking on an existing report item in the design tool and choosing the export to library function. Libraries can also be constructed from scratch, in a similar fashion to building a report design.

Figure 2: BIRT Pipeline

The BIRT engine processes the report in two phases called generation and presentation, as shown in Figure 2, and these two phases can be executed in one or two separate processes. The example BIRT Java Web app (WebViewer) and the Report Engine API allow both possibilities. In the WebViewer, this feature is controlled using a servlet mapping. If you are using the Report Engine API, different method calls are available to determine how the report is executed.

During the generation phase, parameters are processed, data sources retrieve data for the report and all report items are prepared and created. Pagination is also handled in this phase. At the end of the generation phase, depending on how the report is being executed, an optional report document is created.  The report document is only created when generation and presentation are executed in two different processes, and its file has the extension .rptdocument. The optional rptdocument file is used to support Table of Contents operations and paginated HTML. As an additional benefit, the report document offers the ability to run the report once and render it many times at a later date and possibly on another machine, without having to access the data sources again. 

The presentation phase then renders to the requested output. Currently BIRT supports HTML, paginated HTML, PDF, DOC, XLS, PPT, ODS, ODT, OPD, and PostScript. 

The BIRT engine is encapsulated in the BIRT report designer, the example WebViewer, and within the Report Engine runtime. This allows a developer to simply deploy the WebViewer to a Java Web app container to run and render the reports, or an Eclipse developer to use the report engine in plug-in format within an OSGi based application (RCP application), or as a set of libraries that can be added to any Java based application (Servlet, Command Line). 

Event Handling

During the processing of a report, BIRT provides event hooks that can be used to alter how the report is generated. For example, the developer may want to use different stylesheets that depend on the date, or hide/unhide specific tables and charts based on predefined external conditions or input parameters. These event hooks can be implemented in Java or JavaScript. Within the report designer, these hooks are exposed with a JavaScript editor and a dropdown list of all event hooks a particular report item supports. BIRT uses the Mozilla Rhino engine for all JavaScript processing.

Figure 3: Event Handlers

In Figure 3, a data set event handler is shown for the beforeOpen event. This handler modifies the SQL query executed. Most report items support events for preparing, creating and rendering a specific report item. In addition, certain report items expose more events.  For example, Charts exposes over thirty events that can be used to customize almost all aspects of a chart.

These events are executed server-side during the creation and rendering of a report. BIRT can also make use of client-side script, which will be discussed in Part Two of this article next month. To implement an event handler in Java, see the BIRT website.

Author Bio: Jason Weathersby was previously the BIRT Evangelist at Actuate Corporation and a member of the Eclipse Business Intelligence and Reporting Tools (BIRT) Project Management Committee (PMC). He is now the Technical Evangelist at Technical Evangelist at Mozilla Corporation

This article first appeared in JAX Magazine:Reality Check in March. To read that and other issues, click here. Stay tuned for Part Two later in the week.

Image courtesy of peretzp

15 May 07:30

HowTo: Build (Sort of) an Instagram Clone with HTML5

by Noupe Editorial Team

  
instafuzz-home-550 When I started out on this app I was only really just interested in seeing if the web platform had really evolved to a point where an app like the hugely popular Instagram app could be built using just HTML, JavaScript and CSS.  As it turns out we can in fact do exactly that.  This article walks you through the technologies that make this possible and shows how it is entirely feasible today to build interoperable web applications that provide a great user experience no matter what brand of browser the user is running.
26 Apr 10:50

Web Developer Checklist and Userium: 2 Useful Helpers for Oblivious Web Developers

by Dieter Petereit

  
checklists-f1-w550

I'll admit, you need not be oblivious to benefit from the two services I am about to introduce you to. It is not easy to keep proper track of all important aspects of clean and modern web design. I'm sure you will have created your own notes, hints, checklists as your experience developed throughout the years. In my case only the painful experiences made me jot things down for future reference. Today's article shows you Userium and Web Developer Checklist. The two can help developers with lesser experience, yet still be of value to more experienced ones who declare themselves a notes grouch.

27 Aug 20:00

jQuery plugins for awesome web typography

by Jean-Baptiste Jung

FitText.js


FitText is a simple jQuery plugin that automatically make a text fit the width of its parent element. Perfect for awesome, responsive headlines!
Download: http://fittextjs.com/

Lettering.js


Although CSS3 and the @font-face directive have definitely improved web typography, it doesn’t offer complete down-to-the-letter control. This is why Lettering.js have been created. If you’re looking for a simple solution to get the control of each individual letter of your headline, then this plugin is for you.
Download: http://letteringjs.com/

Kern.js


When I create design or front-end code, I love being able to test things in my brother. Kern.js is not a jQuery plugin, but a bookmarklet that allow you to edit texts from websites: Make them bigger, rotate letters, add space… A very useful tool for testing and finding new possibilities.
Download: http://www.kernjs.com/

SlabText.js


SlabText is a very useful jQuery plugin that splits headlines into rows before resizing each row to fill the available horizontal space. Basically, it means that your headline will always look great whatever of the client screen size. A must-have for responsive websites!
Download: http://www.frequency-decoder.com/2012/01/08/slabtext…

Bacon.js


Bacon is a jQuery plugin that allows you to wrap text around a bezier curve or a line. Very cool for magazine-like wrapped text effects!
Download: http://baconforme.com/

Approach


Approach is an interesting plugin if you’re looking to give a text (For exemple, a call-to-action button) a special effect to attract the reader attention. This plugin works in a very similar manner to jQuery animate, but it animates over distance instead of time. The closer you get to the text, the more the style will be applied.
Download: http://srobbin.com/jquery-plugins/approach/

Arctext.js


Here is another cool plugin, based on Lettering.js, which arrange each letter along a curved path. Can be really nice for titles, headlines or other fancy texts!
Download: http://tympanus.net/codrops/2012/01/24/arctext-js-curving…

jMetronome


According to 24ways.org, vertical rhythm is the spacing and arrangement of text as the reader descends the page and is contributed to by three factors: font size, line height and margin or padding. All of these factors must calculated with care in order that the rhythm is maintained.

jMetronome is a jQuery plugin which can take care of maintaining a correct vertical rhythm on your pages, even if they contain media elements such as images or videos.

Download: http://www.fortes.com/2008/jmetronome-using-jquery-to-keep-typographic-rhythm

15 Feb 00:00

App

If I click 'no', I've probably given up on everything, so don't bother taking me to the page I was trying to go to. Just drop me on the homepage. Thanks.