Friday, March 27, 2015

Disable Text Selection with CSS - Six Revisions

Disable Text Selection with CSS - Six Revisions


Disable Text Selection with CSS

Posted: 27 Mar 2015 07:00 AM PDT

There might be some instances where preventing certain parts of your web page from being selected could be beneficial. In these cases, you could try using the user-select CSS property.

Example

Here’s a style rule for a class named disable-selection that, when applied to an HTML element, will prevent people from being able to select the element:

.disable-selection {       -moz-user-select: none; /* Firefox */        -ms-user-select: none; /* Internet Explorer */     -khtml-user-select: none; /* KHTML browsers (e.g. Konqueror) */    -webkit-user-select: none; /* Chrome, Safari, and Opera */    -webkit-touch-callout: none; /* Disable Android and iOS callouts*/  }  

Some details about the style rule:

  • -webkit-user-select is for Chrome, Safari and Opera (there’s no need for -o-user-select)
  • An unprefixed version of the user-select property was purposely left out.
  • The -webkit-touch-callout property disables the callouts that pop up during touch events (on iOS and Android). See following image for reference.

Callout in iOS

Demo

Demo of disabling text selection

View demo

Important Things to Keep in Mind

There’s a catch: user-select is not a standard CSS property included in any W3C specification. Although user-select has a good level of browser support, utilizing the property requires vendor prefixes.

In the prior example, I didn’t use an unprefixed user-select property declaration. That’s because there’s no such property in the eyes of web standards. I would go so far as to analogize the use of user-select as being equivalent to using a proprietary CSS property such as Internet Explorer’s -ms-filter or -ms-text-kashida-space.

Other things to note:

  • user-select is buggy and inconsistent. Sometimes you can still select the text, especially when you start by selecting portions of the UI which aren’t disabled.
  • Using the “Select All” command will occasionally include disabled texts. (Win: Ctrl + A/Mac: Cmd + A) This situation can clearly be seen in Internet Explorer 11.
  • This technique is not a bullet-proof way of preventing user-selection. CSS can easily be disabled. This technique relies on non-standard CSS properties, which means there’s a whole deal of uncertainty with regards to its continued support in future web browsers.
  • Disabled user-selection is annoying. I would use this technique within the framework of progressive enhancement: Use it only in situations where it will enhance the UX of people who use browsers and devices that support the user-select property. I would not, however, assign this to a broad CSS selector like the universal (*) selector or body.
  • The user-select property might invalidate your stylesheet. If standards compliance is important to you, using this property might give you issues when using validator tests such as the CSS Validation Service when set to its strictest options.

Browser Support

Last updated: March 2015

Browser Version Support
Chrome 6
Firefox 2
IE 10
Safari 3.1

Mobile

Browser Version Support
Chrome (Android) 2.1
Safari (iOS) 3.2

Related Content

Jacob Gube is the founder of Six Revisions. He's a front-end developer. Connect with him on Twitter and Facebook.

The post Disable Text Selection with CSS appeared first on Six Revisions.

Thursday, March 26, 2015

1stwebdesigner

1stwebdesigner


Mobile SEO – Can You Optimize For User Experience And Google At The Same Time?

Posted: 26 Mar 2015 06:00 AM PDT

Unlike many years ago, you can’t just be satisfied to only meet your needs in today’s web environment. Instead, you need to please two factors equally: the user and the Google robots ranking you.

The question, however, is which one should you try to please first?

google

Google vs User? Which one to please first?

User Experience vs Google Search Optimization?

There is no need to prioritize because you have to please both Google and your users,  a practice that comes highly recommended. In doing the process, you don’t need to invest in an insane amount of resources into the process where the return might make or break you and your online solution.

By adopting these two requirements, you will be able to rank higher in Google and people will be able to find you much easier than before. With the great web user experience you give your visitors, they will want to recommend you to others.

user

Start with the user.

Part 1. Start With The User

There is no need to prioritize, as mentioned earlier, but you need to start somewhere. Focusing on the experience you give your users is a good starting point for your web solution whether it is a simple website, a web application, or a complex back-end software.

At the base of each of your projects, you have to consider the user. Without the user, you won’t move forward regardless of how much you try to. You’ve heard of the term User Experience (or UX) before, but what does it mean for your product? As much as I hate to tell you this, it depends. Users will not put a price on the same elements in two different web solutions. On top of this, your audience will also react differently to what your competitor has although your product does basically the same.

Finding out what your audience reacts positively to is such a complex matter to discuss that it should have its own article; therefore, we won’t dive too much into what’s in the mind of your users. However, whatever your business is, the lack of investing into user experience will always backfire. Always! Luckily for you, wherever your users come from and whatever their pursuit is, they will always appreciate these following elements that will give them a great product experience.

responsive

Nowadays you must have a responsive website.

Be Responsive Already – Have A Responsive Website!

You’ve probably heard this thousands of times. Unfortunately, I still see so many examples out there of websites that are not responsive yet. It has been more than three years since media queries have become W3C standards but why hasn’t everybody adopted them yet? If it’s something that gets me out of my mind, that is ignorance for the widely accepted standards. Don’t be ignorant with your web solution because you’re playing with the chances of your own project.

I have a difficult time believing that you don’t know much about responsive web design yet. But if you really don’t (dude, seriously?), get this book. Read it from cover to cover, then read it again. It’s been written relatively recently and it’s considered as “responsive web design 101″ for 2015.

responsivetext

Do you know how readable your website is on mobile or tablet?

Responsive Design Typography

Yes, I’m still holding on to this responsive madness topic. Typography is such an important part of a website that ignoring it will score you some negative points with your readers. It is often easy to read text on desktop but God I’ve squinted my eyes a lot in the past years trying to decode simple text on mobile. I hate that, don’t make me do it – ever again! I will leave your site quicker than a Ferrari in pole-position without any chance of returning ever again.

Improving typography for portable devices is not that big of a deal. If you don’t have basic typography training, it is always a safe bet to increase the font size and the line height. Never use a font that is smaller than 14px on mobile (get used to the idea of having at least 16px, no more than 8-9 words per line) and line height that is at least 18px. This will make the text easier to read. Keep headlines short and make it clear. They are headlines so you need to use big font size and bold with a maximum of four words per line.

Web fonts are quite the big deal in typography lately and I advise you do make use of them. They will save you money and time plus, they are SEO-friendly. Just to make sure there is a check on everything, always have a fall-back typeface in case a browser doesn’t download custom web fonts.

When you write copy, make sure to break paragraphs into smaller chunks of text. Take a look at the image below and think of which would you rather read should you end up with only one choice.

Text comparison

The text is the same, the only difference being good formatting and better typography on the right.

The Art Of Negative Space

This article is not supposed to be a crash course in graphic design but there are so many things a good graphic designer can do to improve the user experience of a website. One of them is using negative space, as this allows the human eye to rest. Your webpage will not feel as heavy if you employ this very well and I advise you to get a good graphic designer to take a look at your website if you feel that it currently is “too heavy” at a quick scan.

contactform

Create live validation of the input fields.

Have Contact and Checkout Forms That Work

Web forms can range from sign-up forms and contact forms to input fields in a check-out process or even a search box. Make sure they work. You’ve probably already checked the code behind ten times and tested it. The forms work as they should. But do they really work?

I’ve got no doubts your code does just what it is supposed to do but this is not just about the back-end. The user doesn’t care about your code. The user wants the forms to work, to give him feedback when feedback is needed and to fill them out as quickly as possible.

By the number of websites doing it poorly, error handling in user forms must be one of the most challenging problems there is – up there with landing on Mars and figuring out teleportation. Let me tell you a secret: it’s actually not that hard.

One thing you can do to ensure less confusion is create live validation of the input fields. That means if you need a phone number from me, make sure I can’t submit the form if there is any kind of text in the field that are not digits. Additionally, if you need a number in a specific format, don’t ask me to write it that way. I don’t care if you need the number in US format but let me write a ten-character number and format it yourself with a snippet of code. How hard can it be?

If I submit the form and there is an error, you need to let me know of the exact error and what I can do to fix it. Don’t – I repeat, don’t! – ask me to fill in all the fields again. That’s where you lost a potential client.

Error handling in forms

Example of error handling in mobile app.

Avoid confusion in the forms by using clear language, clear placement and clear colors. The example above is an almost perfect one. There is no doubt about what you need to correct and the error message can’t be missed.

It would be perfect if the error message would also point out the error: Please enter a valid email address. Unfortunately “.xom” is not a valid domain. It would require more code, but users will have no doubt understand why the error appeared in the first place.

If you want to get better at handling error messages in input fields, Christian Holst wrote a great article three years ago about this which is still relevant today.

It’s well known that drop-off rates for long web forms are huge, but they are avoidable. If a user starts to fill in a form, it’s because he wants to. If he stops before he is done, you’re at fault. Most of the time it is because you ask for a big investment from them – bigger than their return.

Would you subscribe to a newsletter if the form requires you to fill in the name, email, address and credit card information? No way in hell. But you would gladly give all these information away if you buy something online. It’s all about keeping a balance between what you ask for and what you give in return.

Shorter forms are always more successful.

In fact, studies show that shorter forms can even convert over 150% better than their longer counterparts. Think about it for a while before adding a new field to your form.

Use SVG Image Format

Use SVG In Your Websites.

Use SVG Image Format Whenever You Can

Some of you might not know what an SVG image is, so I will explain it to you very briefly. SVG stands for Scalable Vector Graphics and, as the name says, it represents a vector image that can be scaled up an down according to the screen it is viewed on.

SVG works very well with CSS and is perfect for responsive web design. Together with responsive typography and responsive layouts it creates a great viewing experience for the user regardless of what device they are on. SVG images are better than normal, rasterized images and even better than font icons simply because they can quickly adapt to the environment while still looking great. Moreover, with font icons you are limited to a single color, while SVG files are much more adaptable when it comes to the colors.

You can use SVG graphics in pretty much everything: logos, UI elements, graphs, icons and many others. SVG is really the future and deserves an article of its own. Luckily, there’s a great one written by the team of Design Your Way.

Check On Design.. Now What Else?

Let me put it down for you: UX is not only design. Remember this. Design is just a part of this big spectrum of elements. There are many things you can do to improve the UX that do not necessarily have something to do with design. It is easy to confuse the two, because most things you create express themselves through visual queues. A good example is the navigation.

navigation

Put special attention to navigation. Make sure it works.

Design Effective Navigation Menu

The navigation menu has to be, without any doubt, the first thing visitors see. The navigation and the logo. Users need to know where they are and where they can go.

A website with poor navigation is like a complex freeway structure without signs. It might be cool to drive your Tesla on it with 175 km/h, but not knowing which exit to take quickly turns into a bit of a problem.

As the starting point of a website, the navigation has to be simple and clean. Don’t cram a lot of unnecessary information into it and at the same time, don’t be vague about it. You can’t afford to confuse your users.

Sometimes it is not that easy to keep your navigation simple; look at Amazon. However, most web designers never get the chance to work on such a complex system, therefore keep in mind: simple navigation is the best navigation there is. Some very simple tips are:

  • to keep the main navigation at the top right (logo on the left)
  • limiting the number of options to no more than 6
  • using short and descriptive words (“Contact” instead of “Hit us up”)
  • having the navigation in the footer if the pages are long and having a navigation that is easy to find and clickable if you are on a portable device.

Other things you can do are quite straightforward. I advise you not to make use of any kind of sneaky tactics or redirects in order to get something you want from the user. He will find out and leave and this will only make him not want to recommend your website.

Badly implemented pop-overs are also something that annoys me as much as anything else. A few days ago I was reading this article on my iPhone from a worldwide-known online magazine. A pop-up came up telling me about cookie usage. That’s fair enough. But there was no button to accept or to cancel. There was no way to exit that pop-up. I’ve clicked on it, I swiped, I pinched, I did everything there is to do.

Actually, I did more than I should have, because the website redirected me to another page (it was probably me clicking on something else without realizing because of the frustration). Now that was a really bad experience. A few seconds after… surprise: the overlay slowly disappeared on its own.

How hard would it have been for them to let me know from the start that this overlay will fade out in 10 seconds? Not much harder than a single line of code, but they still left it out and frustrate me instead.

Depending on who your audience is, there are probably some other tips I could write about but it would take a while. An in-depth analysis is on the table for an article a bit further down the road but you should be set for now. If you master these first tips, you are halfway through to a successful web solution.

Now, for the second part, what do those darn Google robots want from you?

happygoogle

Do you know what Google wants from you?

Part 2. Make Google Happy

It is not only important to make the user happy, it is also important to make sure Google ranks your website well, otherwise, nobody will find you. You will notice, however, how following some of the tips in the first part of the article will also help with the second part.

Make Your Website Responsive (again)

According to many sources online, including Social Media Today and Google itself, it is highly recommended to have a responsive web design for your website. Starting April 21st 2015, Google is going to make some small changes to its search algorithm making it easier for users to find mobile content. Mobile friendliness is something Google looks very seriously into and although nobody actually said that Google will rank mobile better than desktop results, many experts believe this is the way the search engine is heading to. With more people browsing from mobile than desktop, it goes without saying that this is the right way to go.

Google’s Zineb Ait Bahajji was quoted saying in a Google Webmaster Help thread that they do not rank mobile better, but they prefer it because it is:

“easier to maintain, it’s future-friendly and we see less configuration errors with RWD (faulty redirects or bad user-agent detection for instance)”

By creating a website that is responsive, you make both your users happy but also Google, and this is rule number 1 to keep in mind.

Is there an SEO disadvantage to using responsive design instead of separate mobile URLs?

Don’t worry about your PageRank. A website that is responsive is better than a website which redirects the users to a m dot version (something like m.1stwebdesigner.com – a practice that was very popular in the beginning of the 2000s). Although the video is one year and a half old, Matt Cutts from Google explains below why.

speed

How fast is your website?

Make Your Website Load Faster

Google loves quick websites, it is as simple as that. Google itself loads incredibly quick and has the same expectations from you. It has been four already years since the search engine started to rank quick websites better and today there is even more emphasis on it than ever before, with more and more people browsing from mobile. I believe this will continue to be an important factor.

Start by testing your website and see how fast it loads. Minimize the number of images and clunky code, don’t use lots of plugins and only embed necessary video. You can quickly minimize the weight of your website by following these tips, but if you want even more help, hire a professional and make use of Google Webmaster Tools.

CDN Network

This is how a simple CDN network looks like, with the origin server in South America.

Not only does your page speed improves the user experience because it minimizes loading times and leads to higher engagement, retention, conversions and lower bounce rates, but it is so important that Google actually developed a tool for it.

PageSpeed Insights is a set of tools that can help you identify performance best practices for your website and can help you automate the optimization process.

One of the easiest things to do for page speed improvement is paying for a better hosting plan. Poor hosting is often the main reason behind websites loading slowly. However, it is also the lack of Content Delivery Network (CDN). CDN is easy to explain. Instead of having a server in the US which everybody in the world has to access, this network makes sure the content of a website is delivered quicker to people who are located in other parts of the world via edge servers, so their requests don’t have to “travel” such a long distance.

content

Create a good content for your visitors.

Content Is (still) King

It is already a cliché, I know, but good content is still the best way to rank high in Google. You want to write really good content with the readers in mind and not for the sake of keywords. There is nothing wrong with having keywords every once in a while, but don’t overdo it and, again, think of the reader. Does the article offer value? Is it long enough? Does it get shared a lot on social media? All these are important if you want to rank better in Google.

“How long should an article be?”

– is a question that I get a lot. It depends but articles that are shorter than 1.000 words don’t have much value to Google unless they are a hit on social media or you are The New York Times. Moreover, if you are The New York Times, you probably don’t care about ranking anymore. However, if you still need to work on that, keep in mind: Google likes long, informational and useful articles.

I also think it is a good idea to keep a balance. I can write an article or 4k+ words at any time, but how many people will read the whole piece? Not many. The consequence will be that not many people will share it on social media. For informational articles on blogs I personally believe between 1.500 and 2.500 words is the sweet spot, so a bit shorter than this article. If you can stay in between these two, you are where you should be and are doing well.

The bottom line of this is that you need to write content that is worth sharing. Offer value, not articles filled with keywords. The guidelines I wrote for you above are good to keep in mind, but quality is still the most important of them. You can write a hit article that is 800 words long and still do better than a 3.000 words article that is written just for the sake of Google. Write for your audience; and do it well!

Learn To Love FeedTheBot: Optimize Your Website For Google

If you want to get a quick overview of your website in Google’s eyes, FeedTheBot is one of the best tools out there. You only have to fill in your website and let the software check it up. After a few seconds it will return with a string of errors that your website needs to straighten up. Start with the most critical ones, but don’t overlook the other ones. The better you do here, the more Google will appreciate your website.

It is important to remember that Google is not a person, but a robot. Google doesn’t get a feel of the user experience you offer to your visitors, so the best it can do is to rank your website after a complex set of parametres. It can be anything from the number of broken links, usage of robots.txt, JavaScript and CSS usage, sneaky redirects, keyowrd stuffing and so on. If you have dynamic content on your website, it is always a good idea to pay FeedTheBot a visit every once in a while and make sure things are still in check.

Mobile SEO Action Cheatsheet

Reading an article like this one and learning what you have to do is the easy part of improving the UX of a web solution – implementing it is the tough part. Now that you know the reasoning behind every and each action to take, we have a cheatsheet for you below, so you can start working on this right away. So, what do you have to do?

  1. Get down and design a great website. Make use of negative space, beautiful colors and good design practices.
  2. Make sure the navigation is clear, easy to use and doesn’t confuse the user.
  3. Make sure your website is responsive. This helps both the user experience and Google to rank you higher.
  4. Wherever you make use of images or UI elements, try to make use of SVG instead of JPG or PNG
  5. Check how your typography responds to a screen change and ensure your type looks great on all devices.
  6. If you have any forms, check them a couple of times (both the code, but also the experience they give in form of errors and validation).
  7. Find a good hosting plan. If you can find a CDN server, go for it, although it is a bt more expensive.
  8. After creating the website, use Google Webmaster Tools and PageSpeed Insights to make the website even quicker. Aim for a loading time of under 1 second.
  9. Start creating good content that is useful to your users. Keep doing this all the time.
  10. Use FeedTheBot to check on other errors and solve the most critical ones first, but don’t forget about the other ones.

Conclusion

There are two factors you have to please today if you want to have an online presence: the user and Google. I feel we’ve already established that. The good part is that by only following a limited set of tips, you can please both in a short amount of time. If you are about to create a new online presence or think of how to improve you current one, this article should be the starting point for you.

We would love to hear from you down below in the comments section. From now on we’re going to publish a couple of times per month on topics closely related to UX, because we want you to become the best web designer that you can be. So let us know what you want to learn more about.

Introduction to CSS Variables - Six Revisions

Introduction to CSS Variables - Six Revisions


Introduction to CSS Variables

Posted: 25 Mar 2015 07:00 AM PDT

This guide talks about a subject matter that’s not yet supported in most browsers. See the browser support section for more information.

CSS variables give us many of the same advantages that classic variables offer up to programming languages: convenience, code-reusability, a more readable codebase, and improved mistake-proofing.

Example

:root {    --base-font-size: 16px;    --link-color: #6495ed;  }    p {    font-size: var( --base-font-size );  }    a {    font-size: var( --base-font-size );    color: var( --link-color );  }  

Basics

There are three main components you should know about when using CSS variables:

  • Custom properties
  • var() function
  • :root pseudo-class

Custom Properties

You already know about the standard CSS properties such as color, marginwidth, and font-size.

The following example uses the color CSS property:

body {    color: #000000; /* The "color" CSS property */  }  

A custom property just means that we (the CSS authors) get to define the property’s name.

To define a custom property name, we need to prefix it with two dashes (--).

If we want to create a custom property with the name of text-color that has a color value of black (#000000 in hex code), this is how we could do it:

:root {    --text-color: #000000; /* A custom property named "text-color" */  }  

var() Function

In order to apply our custom properties to our work, we have to use the var() function, otherwise browsers won’t know what they’re for.

If we want to use the value of our --text-color custom property in our p, h1, and h2 style rules, then we need to use the var() function like this:

:root {    --text-color: #000000;  }    p {    color: var( --text-color );    font-size: 16px;  }    h1 {    color: var( --text-color );    font-size: 42px;  }    h2 {    color: var( --text-color );    font-size: 36px;  }  

The example above is equivalent to:

p {    color: #000000;    font-size: 16px;  }    h1 {    color: #000000;    font-size: 42px;  }    h2 {    color: #000000;    font-size: 36px;  }  

:root Pseudo-class

We need a place to put our custom properties in. We can specify custom properties within any style rule, but many times, that’s not a good idea because specifying custom properties all over the place presents maintainability and CSS-readability challenges.

The :root pseudo-class represents the top level of our HTML documents. This selector is a good place to put our custom properties in because we can predictably overwrite the custom property values through other CSS selectors that have greater specificity.

Benefits of CSS Variables

Maintainability

Within a given web development project, we’ll often be reusing certain CSS property values. We’ll often reuse colors, line heights, margins, font sizes and so forth.

Here’s an example of four style rules that could benefit from CSS variables:

h1 {    margin-bottom: 20px;    font-size: 42px;    line-height: 120%;    color: gray;  }    p {    margin-bottom: 20px;    font-size: 18px;    line-height: 120%;    color: gray;  }    img {    margin-bottom: 20px;    border: 1px solid gray;  }    .callout {    margin-bottom: 20px;    border: 3px solid gray;    border-radius: 5px;  }  

The problem surfaces when we need to change certain property values later on.

If we manually change our values by hand, it might take us a lot of time, and there’s a huge chance we’ll make an error somewhere, especially if our stylesheet is huge. Similarly, if we perform a batch find-and-replace, we might unintentionally affect other style rules.

We can rewrite the above example using CSS variables:

:root {    --base-bottom-margin: 20px;    --base-line-height:   120%;    --text-color:         gray;  }    h1 {    margin-bottom: var( --base-bottom-margin );    font-size: 42px;    line-height: var( --base-line-height );    color: var( --text-color );  }    p {    margin-bottom: var( --base-bottom-margin );    font-size: 18px;    line-height: var( --base-line-height );    color: var( --text-color );  }    img {    margin-bottom: var( --base-bottom-margin );    border: 1px solid gray;  }    .callout {    margin-bottom: var( --base-bottom-margin );    border: 1px solid gray;    border-radius: 5px;    color: var( --text-color );  }  

Now imagine your client says to you that the text on the screen is hard to read because the text color is too light. In this situation, we just need to update one line in our CSS:

--text-color: black;  

That’s -66% fewer lines of code we have to edit, in the context of the previous set of style rules (one line versus three lines)  .

In the same token, using CSS variables gives us an easier time when we want to experiment with our designs. While we’re developing the project, we can rapidly test color values, line-heights, and bottom-margin values all in one place, and we’ll be able to see the effects in a holistic way.

Improved CSS Readability

Custom properties can help make our stylesheets easier to read. It could make our CSS property declarations more meaningful as well.

Compare this:

background-color: yellow;  font-size: 18px;  

To this:

background-color: var( --highlight-color );  font-size: var( --base-font-size );  

Property values like yellow and 18px don’t give us any useful contextual information. But when we read custom property names like --base-font-size and --highlight-color, even when we’re reading someone else’s code, we instantly know what the property value is doing.

Things to Keep in Mind

Case-sensitivity

Custom properties are case-sensitive (unlike regular CSS properties).

:root {    --main-bg-color: green;    --MAIN-BG-COLOR: RED;  }    .box {    background-color: var( --main-bg-color ); /* green background */  }    .circle {    BACKGROUND-COLOR: VAR(--MAIN-BG-COLOR ); /* red background */    border-radius: 9999em;  }    .box,  .circle {    height: 100px;    width: 100px;    margin-top: 25px;    box-sizing: padding-box;    padding-top: 40px;    text-align: center;  }  

In the above example, there are actually two custom properties that have been defined: --main-bg-color and --MAIN-BG-COLOR.

Custom Property Value Resolution

When a custom property is declared more than once, the assignment follows normal CSS cascading and inheritance rules.

In the following example, the link will be assigned the color of red because the .container selector has greater specificity compared to :root and body.

HTML

<body>    <div class="container">      <a href="">Link</a>    </div>  </body>  

CSS

:root {    --highlight-color: yellow;  }    body {    --highlight-color: green;  }    .container {    --highlight-color: red;  }    a {    color: var( --highlight-color );  }  

However, if we remove the .container style rule from our code, the link will be assigned the color of green because body now becomes the next selector that matches our links.

Fallback Values

You can assign a fallback property value when using the var() function notation. Simply provide the fallback property value as an additional argument delineated with a comma (,).

In the following example, the .box element is supposed to be rendered with a black background. However, because there’s a typo when referencing the custom property name, the background will be rendered using the fallback value (i.e. red).

HTML

<div class="box">A Box</div>  

CSS

div {    --container-bg-color: black;  }    .box {    width: 100px;    height: 100px;    padding-top: 40px;    box-sizing: padding-box;    background-color: var( --container-bf-color, red );    color: white;    text-align: center;  }  

Invalid Values

Beware of assigning CSS properties with the wrong type of value.

In the following example, since the --small-button custom property is given a length unit, its use within the .small-button style rule is invalid.

:root {    --small-button: 200px;  }    .small-button {   color: var(--small-button);  }

A good way to avoid this situation is to come up with descriptive custom property names. For instance, naming the above custom property --small-button-width makes its improper use unlikely.

Browser Support for CSS Variables

Last updated: March 2015.

Desktop

Browser Version Support
Chrome None
Firefox Version 31
IE None
Safari None

Mobile

Browser Version Support
Chrome (Android) None
Safari (iOS) None

Information covered in this guide uses the latest version of W3C CSS Custom Properties for Cascading Variables Module Level 1 as a reference.

Related Content

Jacob Gube is the founder of Six Revisions. He's a front-end developer. Connect with him on Twitter and Facebook.

The post Introduction to CSS Variables appeared first on Six Revisions.

Why Use CSS Preprocessors? (Open Thread)

Posted: 21 Mar 2015 07:00 AM PDT

CSS preprocessors like Sass and Less are now a common part of our workflows. They have their pros and cons, and I’d like to start a discussion about their value to our work.

Some possible talking points (up to you, though):

  • Do you use a CSS preprocessor? Why or why not?
  • What are the benefits and disadvantages of using a preprocessor?
  • Which preprocessor do you use? And, more importantly, why?
  • Got tips and things-you-wish-you-knew’s to share to those of us thinking about using a preprocessor for the first time?

The floor is yours. See you in the comments!

What’s the deal with these open threads?

In my post about the Six Revisions redesign, I shared to you that one of the things I wanted to work on was creating more chances for us to talk and engage with each another. Open Threads is hopefully a small step towards this.

I want to try this concept out and get your feedback before formally codifying any sort of community guidelines, but a couple of basic ground rules:

  1. We’ll only keep the threads open for a short time: I’m thinking this period should be between three to five days, but I’d like to get your feedback on this. The current thread will be open from Saturday until Wednesday, then the comments section will be closed. This way, you won’t come in here six months from now after we’ve have already moved on from the topic.
  2. Let’s be civil: There might be instances where a topic we’re talking about leads to disagreements, which is OK. When this happens, let’s promise each other not to let our passion about our viewpoints take us down towards name-calling, flame wars, and so forth. Instead, let’s offer each other constructive counter-arguments when replying to comments that are contradictory to what we believe in.

Anyways, I’m excited to hear your thoughts about the subject of this open thread. CSS preprocessors are really interesting to me, and I wanted to see what you felt about them.

The post Why Use CSS Preprocessors? (Open Thread) appeared first on Six Revisions.

Bower Beginner’s Guide

Posted: 20 Mar 2015 08:00 AM PDT

Modern web development generally involves using third-party dependencies: CSS libraries and preprocessors like Bootstrap and Sass, JavaScript libraries like jQuery and Angular, and everything else in between.

I bet if you listed down all of the tools you currently use/have used to develop sites with, you’d be shocked at just how many of them you’ve been relying on.

How do you effectively keep track of them all, across all of your various development projects? How do you keep your project dependencies updated? How do you update them in such a way that your older projects, which might not be compatible with the latest releases, aren’t affected?

Managing all of your project dependencies manually is a full time job all on its own. Without the proper tool.

If you work on a lot of dev projects and you use third-party dependencies, using a package manager such as Bower is a must.

Bower front page

This tutorial covers the basics of Bower. This tutorial is geared towards front-end developers who are new to Bower, but are not new to command-line interfaces (CLIs).

If you’re not comfortable with CLIs, Bower is an excellent and gentle introduction to them (compared to, say, jumping directly into managing your own web server/VPS through a command-line interface).

What is Bower?

Bower is a tool that helps you install, update, and manage all of your front-end development dependencies. A dependency in this context is an open source project that you rely on to build your site, such as Bootstrap, jQuery, and Normalize.css.

Bower is similar to npm, except Bower is specifically geared towards front-end developers (HTML, CSS, and JavaScript).

Install Bower

To install Bower, you’ll need:

  • Node
  • npm (which comes with Node by default)
  • Git

If you don’t have Node (and npm) installed yet, you might want to read this tutorial first: How to Install Node.js. If you don’t have Git either, check out our tutorial called How to Quickly Get Started with Git — it’s written by Tobias Günther (who knows a thing or two about Git, given that his company built one of the most popular Git graphical user interfaces in the market).

Once you have Node, npm, and Git ready to go, install Bower by running the following command in your command prompt/terminal:

npm install -g bower

The command above installs Bower globally, which means it will be accessible anywhere in your computer.

Just a funny aside, the command above is similar to using Mozilla Firefox to download Google Chrome. Anyways, moving on.

Next, navigate to your project’s directory/folder. This is important — and I want to say this early on in this tutorial — because the rest of the tutorial assumes you’re already in your project’s directory. If you don’t have one, just create a folder somewhere in your computer, name it something like “bower-tutorial” or “messing-around-with-bower” or whatever, and then navigate to it. You don’t want to be doing all of this in your Desktop folder or something.

Getting Help

Since this is probably your first time using Bower, the command I’d like to talk about first is the help command, which displays inline docs and tips.

Issuing the help command without any arguments will show you a list of Bower commands.

bower help

If you want to learn about a particular Bower command, there are two ways to go about it.

The first is to issue the help command followed by the name of the command you want to learn more about. For example, let’s say you want to learn about the prune Bower command. We can do:

bower help prune

Bower help command results.

The other method is to type the command followed with the -help (or its shortcut, -h) option. This way of displaying help documentation is useful when you’re typing a Bower command and then, midstream, you suddenly realize you’ve completely forgotten what the command does, or that you’d like to explore what its options are before issuing the command.

bower prune -help

The following is exactly the same as bower prune -help, except we’re using the short version of the -help option, which is -h:

bower prune -h

By the way, Bower command options will often have shortened versions to make them easier to type. For example, the --verbose option can also be written as -v and --force can be written as -F.

Find Bower Packages to Install

To locate Bower packages you might want to install, you can use the search command followed by a keyword or the package’s name.

For example, if we’d like to look for packages tagged with the keyword “responsive”, we can issue this command:

bower search responsive

Bower search keyword

If you already know the name of the project you want to install and want to see if it’s available as a Bower package, you can type its name instead. The package name is equal to the project’s GitHub repository name. For instance, if we’re interested in seeing if HTML5 Boilerplate has a Bower package, and we know that the project’s name is “html5-boilerplate”, we can type:

bower search html5-boilerplate

The command will return all the Bower packages that match the package name you’ve entered.

Bower search by package name

If you’d rather use a web interface, you can hit up Bower’s search page.

Get Information on a Package

In the above example, you can see that Bower returned several results when we did our search command. If you’re not sure which package you want, or if you’d like to learn more about a particular package, issue the info command followed by the package name.

Let’s output some information on Bootstrap.

bower info bootstrap

The command will display the contents of the bower.json manifest file of the package — we will talk about bower.json later on — which typically contains details like the package’s official site, a description of the project, the project’s license, keywords, other available version releases, etc.

Results of Bower info command

Installing Bower Packages

The main way to get Bower packages into your project is through the install command followed by the package name you want to install. All the packages you install will go into a folder called bower_components that will be automatically created in your project’s folder.

Let’s grab the jQuery package. We can do so using this command:

bower install jquery

The command will get the latest version of jQuery.

Installing a Specific Version

By default the install command will get the latest version of the package. But if you want to use another version, you can specify the version name.

Perhaps you’re feeling a bit adventurous, and would like to use a not-yet-stable release candidate version, or maybe you want to use an older version that’s compatible with an old project you’re working on, or you’re doing some sort of backwards-compatibility testing. To do this, we just need to specify the version number, preceded by a hash (#).

I recommend issuing the info command first so you can see all the available versions of the package.

Doing bower info jquery, for example, revealed several available versions of jQuery.

Bower info on jQuery package

If we wanted to install an old version, like version 1.11 for example, then this is the command we’d use:

bower install jquery#1.11

Setting Up Your Own Bower Package

A lot of us use the same set of dependencies in our development projects. And some of us even have multiple sets of dependencies, like one set for our personal projects and another set for work-related projects.

You may have found yourself always using the same third-party dependencies — Sass to write CSS, Angular for front-end functionality, HTML5shiv to support old browsers, etc. — throughout your different development projects. It would therefore be more efficient and manageable to set up a sort of template for your dependencies.

We can do this by creating our own custom Bower package. This is done by creating a manifest file called bower.json in the root folder of your project.

You can create bower.json manually using a text editor or source code editor, but it’s just more convenient to do this through the command line using the init command.

bower init

Issuing the init command will give you prompts for filling out details about your Bower package, such as its name, version, description, etc.

Creating a bower.json manifest file

If you already have other Bower packages installed prior to running the init command, Bower will ask you if you want to include them as dependencies in your bower.json file.

Next, we will include other packages to our own Bower package by specifying them as dependencies. We do this by issuing the install command with the --save option (or its shortcut -S) to let Bower know we want to include the package we’re installing in our bower.json manifest file.

Let’s set up the package to include jQuery, Normalize.css, and HTML5shiv.

bower install jQuery --save
bower install normalize.css -S
bower install html5shiv --save

Note: For developer tools such as code linters, CSS compressors, and unit tests — i.e. packages that are only used during development — use the --save-dev option instead. This will include the package in your bower.json as a developer-dependency (which are listed under the devDependencies JSON object in your manifest file).

Now whenever you want to install your packages in another web development project, just use the Bower install command followed by the location of your custom Bower package. Then, if you want to customize your packages for that new project, you can modify its bower.json file.

If you would like to configure your bower.json file manually, or add other settings beyond the ones created by bower init, read Bower’s JSON specifications.

Useful Bower Commands

Here are a few other basic commands that will surely help. (To see all the Bower commands, go to Bower’s list of commands.)

See All of Your Bower Packages

If you’ve stepped away too long from a dev project — let’s say you’re doing maintenance or redesign work for a client a couple of years down the line — a useful command that will remind you which packages you used in the project is the list command.

bower list

What’s great about this command is Bower will also check to see if there are new versions of your packages available. Below, you can see that there are new versions of the packages I’m using:

Updating Your Packages

It’s crucial to, at the bare minimum, update your third-party dependencies whenever there’s a security patch. Doing this manually across all of your dev projects (to put it mildly) is quite time-consuming, tedious, and error-prone.

But with Bower, all you need to do is issue the update command.

To update a specific package, just use the update command followed by the package name. Let’s update jQuery:

bower update jquery

Using the update command without any options or a package-name argument, Bower assumes you want to update all outdated packages.

bower update

Uninstall Bower Packages

If you want to remove a package, just use the uninstall command:

bower uninstall jquery

Uninstall Dependencies

If you want to remove a package from your bower.json list of dependencies, use the uninstall command with the --save option:

bower uninstall html5shiv --save

Conclusion

In this tutorial, we covered the basics of Bower. This tutorial covered the following:

  • Installing Bower
  • Displaying help docs for Bower commands and options
  • Finding and getting information about Bower packages
  • Installing Bower packages
  • How to create your own Bower package
  • Other useful Bower commands for managing your project dependencies (listing, updating, and uninstalling)

In other tutorials, we’ll be exploring intermediate and advanced Bower features such customizing your Bower configuration and Bower’s Programmatic API.

Jacob Gube is the founder of Six Revisions. He's a front-end developer. Connect with him on Twitter and Facebook.

The post Bower Beginner’s Guide appeared first on Six Revisions.

How to Test Responsive Designs

Posted: 18 Mar 2015 07:00 AM PDT

Testing your responsive web designs is crucial because the user experience on mobile devices is quite different from desktops.

But actual testing on all the mobile devices in the market isn’t practical for most of us.

So a simple responsive design testing technique some of us do is resizing our browser’s window size to kind of match the viewport sizes of smartphones and tablets. This is a quick-and-dirty trick for basic visual testing and it help us spot major problems, but it’s a terribly inaccurate portrayal of the mobile device experience.

Mobile devices have unique touch interactions like swipes and pinch-to-zooms, and likewise desktops have interactions like hovering and right-clicking. Responsive designs must account for these variances.

This tutorial will discuss an effective and practical method for debugging and testing your responsive designs. It involves a tool you probably already  have: Google Chrome.

Google Chrome’s DevTools has a feature called device mode that’s loaded with helpful tools for testing and debugging responsive designs.

Device mode is unprecedented. Most other responsive design testing tools simply resize your viewport, but device mode actually emulates the mobile device experience, particularly touchscreen interactions like tapping and swiping, right in your web browser.

Here’s a run down of device mode’s main features:

  • Mobile device emulation: Device mode has accurate models for popular smartphones and tablets (e.g. iPhone, Galaxy, BlackBerry, Kindle, Nexus, and a ton more) that simulates how your responsive designs look and function on touchscreens. It even spoofs the UA string to match the particular device you’re testing so that you’re getting a very precise design preview of your work.
  • Touch events emulation: This feature allows you to experience your designs as if you were interacting with them on your smartphone or tablet.
  • Media queries inspector: This is a ridiculously useful feature that shows you all your media query breakpoints. Clicking on a breakpoint resizes your design’s preview, so you no longer have to manually resize your browser window.
  • Mobile network simulation: mobile internet connectivity is different from our machine’s high-speed broadband connection. Also, many parts of the world still don’t have access to faster mobile internet technologies like LTE. Device mode can show you how your designs perform on EDGE, 3G, LTE, DSL, and WiFi to help you identify potential web performance problems.

To start using device mode, open up your web design in Google Chrome.

Then, open Developer Tools by clicking on Chrome’s menu and then choosing More tools > Developer Tools. The keyboard shortcut for opening Developer Tools is Ctrl+Shift+I (Win) or Option+Command+I (Mac).

How to open Developer Tools

You should now see the Chrome Developer Tools (abbreviated as DevTools from now on) panel at the bottom or on the right of your browser’s viewport.

Developer Tools when opened

Click on the device mode icon (it’s a super tiny button that looks like a smartphone) to toggle device mode on and off.

Device mode icon

When device mode is turned on, you’ll see something along the lines of the image below, and the smartphone icon will turn blue:

Device mode appearance

Responsive Design Testing on a Specific Mobile Device

Use the Device panel to emulate the experience of a particular mobile device. This will allow you to visually test your design on said mobile device, as well as test touch-like interactions.

Device mode

Let’s say we’d like to see how our responsive design looks and functions on an iPhone 5. All we’ll need to do is  select that device in the <Select model> dropdown list:

iPhone 5 testing

Device mode will change the design preview so that you’re seeing what an iPhone 5 user might see. What’s more, if you notice, your mouse cursor is now a circle. When you move your mouse up and down, the design preview will scroll up and down, simulating the swipe interaction behavior. Moving your cursor over a link won’t act like you’re hovering over it (because there’s no hover on touchscreens).

Animation showing touch interactions

Media Queries Testing/Debugging

Debugging and testing your media query breakpoints  is super easy when you’re using device mode. Just click on the the “waterfall” icon at the top-left of device mode and it will show you a bar graph of your breakpoints.

Also, hovering over the “waterfall” icon will display the number of media queries there are on the page you’re testing.

Media query testing

Clicking on the bars will immediately switch the design preview to that media query breakpoint. Switching back and forth between your media queries is quick, making this feature quite a huge time-saver.

The colors of the media query bars are indicative of the type of media query being represented: Orange is a min-width media query, blue is a max-width media query, and green is a min and max range media query (e.g. @media (min-width: 320px) and (max-width: 640px)).

Related article: Design-Based Media Queries

Mobile Internet Testing

You can test the perceived performance of your responsive design by using the Network feature of device mode. Click the Network dropdown menu and choose the mobile network technology you want to test with, such as EDGE or 3G. This feature will throttle your Internet connection to match your chosen network technology.

Mobile internet connectivity emulation

Conclusion

DevTools is an incredibly powerful tool, and device mode makes it an even more indispensable part of the modern web designer’s toolkit.

There are a few more features in the device mode for you to explore, such as:

  • Changing the devicePixelRatio in the Device panel for testing the UX on Retina displays
  • Vertical/horizontal rulers on the top and left of the viewport to help you eyeball certain pixel lengths
  • Manual override of the UA string (the text field at the bottom of the Network panel)

Share your strategies for responsive design testing in the comments below. Do you have tips to share about device mode?

Related Content

Jacob Gube is the founder of Six Revisions. He's a front-end developer. Connect with him on Twitter and Facebook.

The post How to Test Responsive Designs appeared first on Six Revisions.

Six Revisions Gets a Redesign

Posted: 17 Mar 2015 01:07 AM PDT

The new site design of Six Revisions was launched a few hours ago (officially named Six Revisions version 2). This is the most significant redesign of the site in years.

The main objective of this new design is to improve your reading and overall experience on the site.

Highlights

There’s still quite a lot of design, web performance, and functionality issues to resolve, but overall this redesign should greatly enhance your experience on Six Revisions.

I’ll briefly walk you through some of the design improvements in the new version.

Responsive Design

Six Revisions readers accessing the site with their mobile device will be pleased to know that the site now provides them a much better reading experience. A quick check on Google PageSpeed Insights shows no issues with mobile UX. (However, I still need to work on mobile and desktop page speed improvements across the site, as well as enhancements beyond PageSpeed Insights suggestions.)

Google PageSpeed Insights results for the Six Revisions front page

Dealing with the embedded code samples (content wrapped in <pre> elements) with wide line lengths was one of the trickier design challenges. I explored a couple of solutions: horizontal scrollbars on code samples that were wider than the native device width, or making long lines wrap to the next line. I chose, last-minute, to go with the latter solution because horizontal scrolling (swiping left-and-right) on smartphones was too disruptive to the reading flow.

Improved Readability

The old web design was aesthetically outdated. It was clunky. It was broken in so many areas and in so many ways. Most importantly, it got in the way of your reading experience on the site.

The new design is optimized to present Six Revisions content in the best way possible, so that the hard work of our authors is no longer being overshadowed by UX, usability, and readability problems created by the previous design. The new UI is clean and simple, and is designed with the intent of complementing your reading experience, rather than being a focal point.

Improving readability, among other things, involved significant time and effort given to designing, evaluating, and testing the design’s typography.

The primary web font used in Six Revisions version 2 is Lato, an extremely legible and pleasant-to-read font designed by Lukasz Dziedzic. It comes in 18 variants and has 3,000 glyphs, making it a flexible and robust font that can handle old, current, and future Six Revisions content.

Sample of Lato font from the type designer's personal portfolio.

Code samples are an essential component of a publication that caters to professional developers and web designers. The font used to present embedded code samples is one of my most favorite programming fonts, Source Code Pro. It works well with the main body font, and it’s simply gorgeous. It’s exceptionally legible, and makes reading code a more delightful experience.

Source Code Pro preview

The site’s typography still needs to be perfected and fine-tuned, so this area is a work in progress.

Improved Site Navigability

One major issue with the old UI was it was tough to navigate to content that you might be interested in.

One feature aimed at improving site navigability is the fixed navigation bar on top of our web pages. This allows you to move throughout the site easily without having to scroll back up to the top of the page. Scrolling back to the top of the page to navigate the site was particularly troublesome in the old design, since Six Revisions publishes long-form articles.

In the future, this navigation bar will display contextual navigation items and information based on where you are on the site to help you discover other articles and tutorials you might be interested in.

I’m in the process of building more interfaces that will make our body of content easier to navigate. For instance, I’m currently developing an interface that makes it manageable to view 50 to 100 Six Revisions articles on a single web page to reduce the amount of time and effort required to transition to another page.

A critical issue right now is that the site search feature is not displaying search results. This is a high-priority bug that I will work on in the next few hours (after I get some sleep).

Better UX for Discussions

One of my main goals is to improve your ability to interact with other members of the Six Revisions community. One of the first steps I took towards this goal was to enable multi-level commenting so that we can all have better conversations in the comments.

My desire is for Six Revisions to become a venue where people from all over the world interested in development and design come together to talk about the subject we’re passionate about.

I’ll be introducing a feature that allows you (and other people on Six Revisions) to view your comment history on the site. Another feature I’m thinking about implementing is social voting in the comments section so that the community gets to decide which comments other readers should pay attention to.

Also, I’ll be developing ways to encourage readers to contribute to the discussions by giving people who regularly share important information and engage in meaningful conversations special avatars, one-on-ones, and so forth.

For now, Gravatar support has been disabled due to web performance concerns. I’m reviewing our options for better avatar support in the comments.

Roadmap

I want to talk about some things you can expect on this site from here on out.

I have a million things I want to share with you regarding the future of Six Revisions, and I can’t fit them all into this post, so I’ll be discussing them in more detail in subsequent posts.

Vision

My mission is for Six Revisions to be a leading source of information on development and design, a place where you go to learn and stay updated on essential topics related to building sites and apps.

Main Topics

These are the core topics that we’ll be covering in the form of tutorials, articles, guides, and other forms of content:

Other subjects that matter to developers and designers will also occasionally be covered. These include project and business management, content strategy, SEO, and general design and code theory.

Content Improvements

The most critical area of concern is the site’s content. Six Revisions hasn’t been publishing articles regularly, and I need to address that right away.

These are some things I’d like to improve on:

Improve publication schedule

Right now, Six Revisions publishes between one to three articles per week.

The first step is to work towards consistently publishing three articles per week (Monday, Wednesday, and Friday). The next objective will be to publish 5 articles a week (M-F). After that, Six Revisions will start to post at least one article a day.

Improvements in the authoring experience

The writing process and incentives for our authors need to be improved. The task of contributing articles to the publication must be streamlined and made easier in order for Six Revisions to be able to publish high-quality articles regularly.

If you’re interested in writing tutorials and articles to be published on Six Revisions, please email me at jacob@sixrevisions.com.

Content archive maintenance

We’ve published over a thousand articles. A lot of them are timeless. However, many are also outdated because that’s just the nature of development and design, things change so much and so frequently. I’ll develop methods that will keep our content up-to-date as much as possible: Facts that are no longer true must be corrected, broken links and other issues will be addressed.

Community Engagement and Transparency

Without you, there would be no Six Revisions.

I will create more engagement opportunities, whether that’s in the form of introducing new discussion features on the site, or simply just having more regular conversations with you in the comments section, social media, and/or email.

Also, I’ll keep you updated with the things that happen behind the scenes. For example, I’ll start posting quarterly reports to give you a status update on Six Revisions.

Design

Right now, there’s still a lot of UI-related issues with the Six Revisions version 2 design. For example, you’ll see some "jankness" when you view the site on iOS devices, and possibly in other devices that I haven’t gotten the opportunity to test with yet (outside of emulators). I will fix these throughout the week.

If I may ask you a favor: Please leave a comment below (or email me) if you spot any issues with the design. Thank you so much.

Other things I’d like to do with the design of the site:

  • Improve rendering performance: Stress-test and benchmark CSS performance, and improve paint times
  • Enhance the site navigation experience: A few key site navigational aids were introduced in version 2, such as the menu bar and better pagination. I will create more interfaces to make Six Revisions content easier to navigate to.

Code

In terms of front-end development, these things still need to be done:

  • Web performance optimization: CSS selectors and media queries need to be optimized, JS and CSS files need to be combined and be served compressed, the average web page file size of Six Revisions must be reduced, the web font has to be moved to our CDN to cut down on DNS lookups, etc. When I’ve tackled the "easy" web performance issues, I will go for more advanced WPO improvements, such as using inline CSS so that only style rules needed to render the page will be included in the request.
  • HTTPS Everywhere
  • Modularize the stylesheet to make continuous site development easier

Wrapping Up

I look forward to your feedback about Six Revisions version 2. I know many of you have been waiting for a better UI and UX on the site.

I’d like to hear your thoughts on the future of Six Revisions. Do you have ideas for improving Six Revisions? What subjects should we cover on the site?

Also, I want to thank you for your continual support of Six Revisions.

About the Author

Jacob Gube is the founder of Six Revisions. He’s a front-end developer. Connect with him on Twitter and Facebook.

The post Six Revisions Gets a Redesign appeared first on Six Revisions.