Tips for Cross Browser Compatibility

Developing and designing for every browser type can be a very challenging (some might say impossible) task. Every browser has its own unique inherent styling that (even with the use of a reset) can be difficult to override or get rid of completely, and not every browser supports some of the newer, cool CSS properties and techniques. For these reasons, it can be really tricky to make sure that your site designs look good and consistent (and functional!) across every single browser. While accounting for cross browser compatibility can be a daunting task, it can be made easier by applying the following tips.

Use Vendor Prefixes

This one is probably the most common way to avoid cross browser compatibility issues. A lot of CSS properties (particularly the newer ones) aren’t supported on most browsers, unless you use a vendor prefix. As a developer, you may want to cover all your bases when using a CSS property that isn’t widely supported (like, for example, the transition property) to make sure that your designs (or in the case of the transition property, your animated effects) actually work in every browser. The following is a list of the vendor prefixes that can be used for every browser:

[css]
-webkit-   //chrome, android, safari, ios
-o-   //opera
-moz-   //firefox
-ms- //internet explorer
[/css]

Here’s how you would use them in context:

[css]
div{
transition: all .5s ease;
-webkit-transition: all .5s ease;
-o-transition: all .5s ease;
-moz-transition: all .5s ease;
-ms-transition: all .5s ease;
}
[/css]

Don’t forget to include hyphens on either side of your prefix keyword!

Browser Hacks

If you want to target a specific property or style rule to behave a particular way based on the browser, there are a number of different CSS “hacks” that will allow you to target a specific browser and apply style rules to HTML elements only if they appear on one particular browser. This works well when you’re trying to compensate for a style or property that might work on all browsers except for one. This way, you can use a hack to single out a specific browser and change the styling only for that one to make sure your design doesn’t look funky or your functionality isn’t compromised without the unsupported CSS property. Check out the list of hacks for common browsers below:

[css]
/* Internet Explorer Versions 9+ */
@<span class="hljs-keyword">media</span> screen and (min-width:<span class="hljs-number">0</span>\<span class="hljs-number">0</span>) {
<span class="hljs-selector-class">.<strong>yourElement</strong></span> {
font-size: 12px;
}
}

/* Firefox Versions 3+ */
<span class="hljs-selector-tag">html</span>><span class="hljs-comment">/**/</span><span class="hljs-selector-tag">body</span> <span class="hljs-selector-class">.<strong>yourElement</strong></span>, <span class="hljs-selector-tag">x</span><span class="hljs-selector-pseudo">:-moz-any-link</span>, <span class="hljs-selector-tag">x</span><span class="hljs-selector-pseudo">:default</span> {
<span class="hljs-attribute">font-size: 12px;</span><span class="hljs-meta">
</span>}

/* Chrome and Safari */
@<span class="hljs-keyword">media</span> screen and (-webkit-min-device-pixel-ratio:<span class="hljs-number">0</span>) {
<span class="hljs-selector-class">.<strong>yourElement</strong></span> {
<span class="hljs-attribute">font-size</span>: 12px;<span class="hljs-number">
</span>}
}
[/css]

Make sure you insert the name of the element you’d like to single out in the spot where it’s written .yourElement in bold.

Use CSS @supports Rule

The CSS @supports allows you to wrap your CSS rules within the @supports query so that the rule will only be applied if it’s supported on a particular browser. If a rule isn’t supported, it’ll get skipped over as if the rule weren’t there, which can really come in handy for those properties you want to use but don’t want to look terrible if they happen to not be supported on a browser. Here’s how you would use it in context:

[css]
@supports(transition: all .5s ease){
div{
transition: all .5s ease;
}
}
[/css]

In order to use @supports, you’ll have to pass through the CSS rule you want to account for as a parameter, and then the code will take care of the rest.

Two Ways to Create an Animated Hamburger Menu

If you’re a developer or a designer, you’re probably familiar with the trend of using hamburger (or three-line) menus as fully responsive and mobile friendly navigation solutions. The trend has grown considerably over time and is becoming even more popular as mobile friendly and mobile first design becomes the norm. In fact, it feels like hamburger menus or three line icons have become a universally recognizes symbol for “navigation menu.” So how do you make yours stand out from the pack? Add some smooth animations, of course! What follows are two different ways to create unique hamburger menus that have animated effects when they’re clicked.

Three Lines to One Line Effect

One cool way to animate your hamburger menu icon is to have the three lines transform into one line when it’s clicked, then have it go back to three lines when it’s clicked again. This can be achieved pretty easily by creating each line of the hamburger menu from HTML and CSS, then creating classes that can be toggled with a jQuery toggle event that will effectively hide the top and bottom menu line when they’re clicked.

Here’s the HTML to start you off:

[html]

<div class="icon-group">
<div class="icon"></div>
</div>

[/html]

As you can see, this icon is created purely from divs. Here’s the CSS you’ll need to use to make those divs look like a three line icon (and to give them some nice style as well!).

[css]

.icon-group {
position: relative;
width: 65px;
height: 40px;
transform: translate(-50%, -50%);
position: absolute;
left: 50%;
top: 50%;
}
.icon-group:hover {
cursor: pointer;
}

.icon {
margin-top: 20px;
position: absolute;
width: 100%;
height: 0.5em;
background: #DB324D;
}
.icon:before, .icon:after {
position: absolute;
width: 100%;
height: 0.5em;
background: #DB324D;
transition: margin-top 150ms;
content: "";
display: block;
margin-top: -20px;
}
.icon:after {
margin-top: 20px;
}

.icon-group.collapsed .icon:before {
margin-top: 0;
}
.icon-group.collapsed .icon:after {
margin-top: 0;
}

[/css]

Your menu icon should now look like this:

Screen Shot 2016-09-23 at 12.40.41 PM

To add the animations, you’ll need to include the following JavaScript:

[javascript]

$(document).ready(function(){
$(‘.icon-group’).on(‘click’, function(){
$(this).toggleClass(‘collapsed’);
});
});

[/javascript]

The code above will toggle the .collapsed class when the .icon-group icon is clicked — this class, when added to the .icon-group div, will actually toggle the top and bottom lines of the icon (this is because of the way we’ve defined them in the CSS — check out .collapsed in the CSS above!). The menu, when clicked, should look like just one line:

Screen Shot 2016-09-23 at 12.40.47 PM

 

Three Lines to X Effect

Another interesting way to animate your three-line hamburger icon menu is to have the three lines transform into an X when it’s clicked. This can be achieved in almost the same was as the previous effect, by having jQuery toggle a particular class when the menu is clicked. To make the lines appear to cross, all you need to employ is the transform property.

Start by creating the elements of your hamburger three-line menu as HTML elements within an <a> tag.

Then style it using the following CSS so that it actually looks like a three-line menu icon:

[css]

.hamburgler {
width: 300px;
height: 300px;
display: block;
-webkit-transition: .3s ease all;
transition: .3s ease all;
}
.hamburgler.no-hamburgler {
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}

.bun,
.meat {
display: block;
width: 100%;
background: #fcd455;
height: 20%;
-webkit-transition: .3s ease all;
transition: .3s ease all;
border-radius: 50px;
}

.no-hamburgler .top {
height: 38%;
width: 20%;
margin-left: 40%;
border-radius: 50px 50px 0 0;
}

.no-hamburgler .bottom {
height: 38%;
width: 20%;
margin-left: 40%;
border-radius: 0 0 50px 50px;
}

.meat {
margin: 20% 0;
}
.no-hamburgler .meat {
margin: 2% 0;
}

[/css]

Your three-line hamburger menu should look like this:

Screen Shot 2016-09-23 at 5.19.05 PM

Use the following JavaScript code to make sure your icon forms an X when it’s clicked:

[javascript]

$(document).ready(function() {
$(‘.hamburgler’).click(function(e) {
e.preventDefault();
$(this).toggleClass(‘no-hamburgler’);
});

[/javascript]

 

Screen Shot 2016-09-23 at 5.19.11 PM

Make sure you include the e.preventDefault(); function or the hamburgler menu will act as a regular link when you click it and could potentially reload the page.

Adding these animations to your hamburger menu icons can really make your icons stand out. In a world where practically everyone is implementing hamburger menus in their designs, it definitely doesn’t hurt to stand out a bit.

 

 

HTML5 Fullscreen Background Video with CSS and JS (Plugin/Library)

Fullscreen background videos that autoplay right when the webpage loads (above the fold) has become quite a popular trend these days. Personally I think a fullscreen good quality video that autoplays does increases engagement for the users/customers. It should be kept in mind that the story of the video must be relevant to the brand. These days we’re surrounded by loads of videos on social networks like FB and Twitter as well which autoplay (but is muted of course). Analytical studies have also reported higher engagement due to this.

Continue reading “HTML5 Fullscreen Background Video with CSS and JS (Plugin/Library)”

Guide (Introduction, Implementation and How it Works) to A/B Testing and Split URL Testing (VWO, Optimizely, Google Analytics)

Recently I’ve been investing a lot of time into A/B (split) testing/experiments and analysing their results. Slowly I’ve started to love this way of rolling out changes on the web (can be surely used for mobile apps as well), as it is a complete data-driven approach and can produce quite surprising (or shocking, how you see it) results at times. With this approach you’ll always know what works (instead of speculating) with firm evidence and eventually drive more sales or signups or whatever that matters to you. That said, I would recommend not A/B testing just anything and everything but always find the right situations or cases that would make sense to experiment. If you’ve enough bandwidth (extra time) then use this approach to keep on analysing your visitor behaviour and draw learnings that help you make more prospects achieve the objectives that you’ve set for them, eventually turning them into customers.

Continue reading “Guide (Introduction, Implementation and How it Works) to A/B Testing and Split URL Testing (VWO, Optimizely, Google Analytics)”

Getting Started with React – Setting up the Development Environment

React (also React.js or ReactJS) is a JavaScript library for building user interfaces developed by Facebook & Instagram. It is not a full blown framework like Angular or Ember or even Backbone.js. It is a very simple View library which can replace the V in any other client-side MVC framework, i.e., you can use Backbone and React together for instance. In fact a lot of people are already doing that. Although when combined with a design pattern like Flux, you can totally give up on an MVC framework for your client-side architecture and happily develop apps with just React in conjunction with the Flux application architecture. React encompasses some interesting concepts too like Virtual DOM, uni-directional reactive data flow, etc. but don’t worry we’ll discuss all those much later when you’re already comfortable with the library and hacking your way through it.

Continue reading “Getting Started with React – Setting up the Development Environment”

Compiling Next Generation JavaScript (ES6, ES7, React) in Browser with Babel 6 and Above

Babel is an amazing tool for writing ES6 (ES2015), ES7 (ES2016), JSX, etc. code that finally gets compiled (or transpiled) into JavaScript (mostly ES5 as of now) that can be executed by most browsers. So basically you can use JS features like classes, promises, etc. without worrying about the browser support as Babel will eventually convert all your code into browser-understandable program.

Continue reading “Compiling Next Generation JavaScript (ES6, ES7, React) in Browser with Babel 6 and Above”

CSS Apply Filter Effects (blur, grayscale, hue) to the Area Behind an Element with backdrop-filter Property

We’re well acquainted with the CSS3 filter property that lets us apply various effects like blur, grayscale, sepia, saturation, etc. to a particular element. Now using this property we actually end up adjusting the rendering of the entire element including its borders, background and content (text or/and image). Did you ever want to apply the same effects to just the area behind the element, i.e., the background of the parent element or the one right behind/below the target element ? This is now very easily possible with the backdrop-filter property. I’m sure you’d have noticed this effect being widely used in iOS 7 and OS X Yosemite.

Continue reading “CSS Apply Filter Effects (blur, grayscale, hue) to the Area Behind an Element with backdrop-filter Property”