Take Advantage of CSS3 to Achieve Subtle Design

Take Advantage of CSS3 to Achieve Subtle Design

Tutorial Details
  • Topic: CSS
  • Difficulty: Medium

I hear this CSS3 thing is all the rage. Resources are flying around the tutorial world and blogosphere providing brilliant examples of creative new ways to design using CSS3 modules. However, it’s easy to over-implement and lose the brilliant subtlety of great user interfaces. Here are three quick tips for using powerful CSS3 techniques in subtle ways.


Preface: It Doesn’t Take Much

People are able to perceive and distinguish very small changes.

The bottom line here is that people are able to perceive and distinguish very small changes that they may not consciously notice or be able to recall. I doubt that this is new information to anyone. It is one of the more well-known concepts put forth by sensation and perception studies. Sometimes, one thing may be pleasing over another. And sometimes, you don’t even know why.

However, keep in mind that web design is a conscious process. Subtle design can be difficult because it is easy to think “that just needs a little more.” Before you know it, the subtlety is lost.

With that in mind, I would like to present three CSS3 techniques that can be used to provide varying forms of subtlety for web design.


1. Transition

Transition is a powerful tool, providing a way for CSS to essentially animate from one endpoint to another. The syntax packs a fairly rich toolset: property, duration, and easing. Each of these pieces can be varied to provide different levels of subtlety. Often, it just takes playing – as effects often do. In other words, play with the values until it seems right. Just don’t drive yourself crazy. It’s easy to get lost tweaking even such a short list of variables.

Example: Color Transitions

It’s not uncommon for navigation items to change color when the mouse is hovering. Transition can make that color change a little smoother.

.nav li a{
	color:#282828;
	text-decoration:none;
	
	-webkit-transition:color .1s ease-in-out;
	-moz-transition:color .1s ease-in-out;
	-o-transition:color .1s ease-in-out;
	transition:color .1s ease-in-out;
}
.nav li a:hover{
	color:#808080;
}

The color change is not subtle here. It’s clearly noticeable. What is subtle is the smoothing of that color change.

The trick to keeping this subtle is the duration. If it’s too long, the effect will be far too noticeable. The navigation can quickly become burdensome to hover over and look amateurish.

View the demo.

Notes about the CSS

In case you haven’t delved into CSS3 just yet, it’s important to note the order in which the browser-specific declarations come. Actually, it’s just important to notice that the non-browser specific declaration comes last in the list. CSS takes the last declaration and makes it more important in the case of a conflict. Once an actual transition spec is released, presumably all browsers will implement the module without needing the proprietary prefix. Thus, your CSS becomes somewhat future-ready at no real cost to the current implementations.

Also, notice that the transitions are in the <a> element style, not its hover. This will provide the transition both on mouse-over and mouse-off.


2. nth-of-type (or nth-child)

The nth-of-type or nth-child selector allows patterns to be declared in a series of elements and apply styles accordingly. For example, in a table, nth-child could color every other row by using :nth-child(odd). Let’s look at an example that may not be quite as clear.

Example: Grouping

We’ll take a pretty standard navigation markup…

<ul class='nav'>
	<li><a href='#'>Home</a></li>
	<li><a href='#'>About</a></li>
	<li><a href='#'>Work</a></li>
	<li><a href='#'>Forum</a></li>
	<li><a href='#'>Blog</a></li>
</ul>

…and apply some styling.

.nav li:nth-of-type(odd){
	margin-top:5px;
}
.nav li:nth-of-type(even){
	margin-top:12px;
}
.nav li:nth-of-type(2n+2){
	margin-right:0;
}
.nav li:nth-of-type(2n+3){
	margin-left:8px;
	margin-right:25px;
}

This will create a staggered-looking menu with a few high items, a few low items, and a couple sets that look paired. The visual difference between this and an in-line menu is clear.

So what’s so subtle about it? The subtlety here is twofold.

  1. The higher items look more important. Perhaps this person wanted to showcase his or her portfolio and blog. Those, along with the Home link, have been pushed up to be slightly more prominent. People’s eyes will be drawn to those links first.
  2. Notice the grouping. About and Work have been grouped together, as have Forum and Blog. This styling groups similar pages in its navigation. Work and About are both viewable things pertaining to the person while forum and blog are more audience-driven and interactive.

So, perhaps a visitor first sees “Home”. That visitor will probably realize that he or she is already on the homepage. He or she may very well see “Work” next. *click*. After viewing some pieces of work, they may well have seen “Blog” next but perhaps the grouping ends up being stronger and their desire is pulled to “About”. The designer is now driving the visitor using a navigational layout. He or she has provided hints as to where visitors should go, sequentially.

Will this happen every time? Absolutely not. Will it happen sometimes? I would bet so.

That’s the point of subtlety. It doesn’t overwhelmingly influence the user, but it might provide some useful hints or motivations now and then.


3. Gradients

Here’s a simple way to introduce subtlety into a design. Ironically, it’s probably got the most complicated syntax out there. Not only that, but it also has significantly different syntaxes between browsers. Let’s take a look.

Example: Forms

Given a pretty simple contact form (email, message), here’s some styling:

form input[type=text],
form textarea{
	background-image:-webkit-gradient(
		linear,
		left bottom,
		left top,
		color-stop(0, rgb(255,255,255)),
		color-stop(1, rgb(248,248,248))
	);
	
	background-image:-moz-linear-gradient(
		center bottom,
		rgb(255,255,255) 0%,
		rgb(248,248,248) 100%
	);
	
	outline:none;
	border:solid 1px #ccc;
}

That’s quite a full declaration, isn’t it? And that only covers two browsers!

I’m not going to go into all of the syntax, because others have done that for me. Refer to “Understanding CSS Gradients” on Nettuts+ for a better understanding. When you’re finished, let’s talk about subtlety.

The gradient in these text areas is almost imperceiveable. However, if you play with the CSS and take out the border, I assure you it is there.

If you still can’t see it in that second image, take your head and move it to the side of your monitor, so that you are viewing the monitor at a pretty steep angle. See it now? If not, I refuse to be held accountable. I see it, so your monitor must be broken. :)

Anyhow, notice how close the rgb colors are in the css. The top of the text input and textarea are shaded ever-so-slightly. This is one example of very extreme subtlety. While filling out a form, it is unlikely anyone will ever notice this gradient. However, people may find your form just a little more appealing than others; even if they don’t know why.


Bonus: Browser Incompatibility

Well, we’ve almost made it through and entire CSS3 article without discussing browser issues. How did we manage that? For one thing, there wasn’t a lot of emphasis on code. More importantly, though, I was saving the best for last.

Subtle changes probably won’t be missed

If you take a look at the demo for this tutorial in a webkit browser, then compare that to a Firefox browser, you will notice some differences. If you step over to IE, you’ll notice even further differences. One nice thing about the use of subtlety is that if the subtle difference isn’t there, people probably won’t notice. In other words, the color change in the first example still works without the transition; it’s just a little less slick. If the only purpose of using nth-of-type was to group based on commonality, no visitor is going to care if that grouping isn’t there. The menu still works. And the gradient? Remember how hard you had to try to notice it even when being told exactly where it was?

That last demo example will definitely be noticed…

Make it an opportunity for creativity, instead of an insurmountable burden.

Probably the most rational opposition to the “different looks in different browsers” approach to web design is that many (perhaps most) clients will want the exact same website in any major browser. If there is no room for budging on this and you need to pay your electric bill, do whatever you need to in order to get that all-important rounded corner into all IE versions back to the dawn of time.

However, some clients can be educated and swayed as to some advantages of having one design in one place and another somewhere else. For example, accepting a slightly different appearance can dramatically cut down on HTTP requests and excess HTML elements, if a lot of images are being used to create borders and shadows and whatnot. Or, if you’re anything like me, you have some personal projects and enjoy a good challenge (like providing the same “experience” cross browser without always having the same layout). Or, maybe you have two different designs that you really like and can’t decide which one to implement. Here’s an opportunity to implement one in one browser and the other in another, driven out of a single stylesheet.

The overall point here is that browser incompatibility is a fact of the current web when trying to utilize CSS3. So, make it an opportunity for creativity, instead of an insurmountable burden.

But what is subtle about that last demo example?

The subtlety here isn’t exactly a design subtlety. Instead, it’s more of a designer subtlety. In my experience, most people only use one browser. Web professionals forget that sometimes, as we install three versions of five different browsers on every machine we come across.

So, if an IE-only user happens across your site and its content is clear and he or she enjoys the experience, you have succeeded in your design. If another user happens across your site in Chrome and enjoys their experience and the content is clear, you have succeeded in your design. And perhaps that visitor appreciated a few extra tid-bits. Kudos. Most importantly, though, if you ever get the opportunity to sit down and watch this happen simultaneously, you will have succeeded in having some subtle fun.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://freecss.info CSS Tutorials

    Great run through. Love the new CSS3 advantages.

  • http://www.nouveller.com/ Benjamin Reid

    I really hope no one ever does that with their navigation on a live site, it just looks broken.

  • http://tomglenn.co.uk Tom Glenn

    I’m with Benjamin on that. The navigation example looks horribly broken.
    So broken in fact, I would probably leave a site if that was the first thing I was greeted with…

  • http://www.code-pal.com Sumeet Chawla

    Pretty cool article Brant. CSS3 is really makes our job very easy :) I also wrote a tutorial on how to use CSS3 to create a slide out panel which helps bypass the use of jquery. The slide out panel obviously works with “transition effects” only in webkit browsers though. But works like normal slide out ( without animation ) on other browsers.

    http://www.1stwebdesigner.com/tutorials/slide-out-panel-css3/

    • w1sh

      I’ve been seeing your site/tutorials a lot lately. Quality stuff, keep it the good work!

  • http://samanthaarmacost.com Samantha Armacost

    -moz-transition ?

    It isn’t going to be implemented until Firefox 4, correct?

    • Brant
      Author

      So I hear.

      It’s just in there as preparation for the future.

    • adrian

      yes, and it can be tested in the firefox 4 beta!

      • Lexihel

        And it looks great (at least most of’em) in Firefox 4!

  • http://www.rentepersoonlijkelening.nl CSS3 is hard :-(

    I’m new with CSS3, this article was a bit hard for me… thanks anyway :-)

  • http://aaronbentley.co.uk Aaron Bentley

    Highly informative tut, nice work Brant.
    Loved the bit about leaving non-browser specific code till the end of the css rule, even more reason to try these new css3 features without causing a lil’ more work for yourself in the future.

  • Mohamed Zahran

    Great tut, but does anyone know when it will be clear to use HTML 5 + CSS 3 without worrying about incompatibility?

    • http://danmesa.com/ Dan

      2012 – 2020 is the estimated range. Relatively safe to use by 2012 and 100% by 2020.

      • Mohamed Zahran

        um, it seems too vast, thanks for your concern.

      • Mads Kjaer

        You can start using HTM5 and CSS3 today! The dates you are mentioning are simply estimated deadlines where the spec will reach draft and recommendation status. You can use the technologies as soon as the browsers implement them, which they are already doing.

        This article demonstrates that you CAN use CSS3 today, without breaking anything. This is the great thing about it – if an older browser doesn’t recognize your fancy new attributes or selectors, it will just skip past them. There is really nothing to worry about, unless you / your clients are really anal about everything looking the same in every browser – which web design is not about.

        If you use coding best practices you will have no problems whatsoever with HTML5 / CSS3. It requires a bit of reading to learn the new stuff, but what doesn’t?

    • http://jayphen.com Jayphen Simpson

      You will always have to have fallbacks in mind, as there is no specific date when IE6/IE7 will fall off the edge of the Earth. Implement progressive enhancement – your product should at least function in all common browsers, and have extra features for those using modern browsers.

      • Mohamed Zahran

        I see, As I read at Software Engineering compatibility is inevitable, but I don’t care about IE6 users since they’re from the stone-age.

        We all wish to take advantage of these modern techniques ASAP.

    • lafncow

      @Mohamed Zahran

      “…compatibility is inevitable, but I don’t care about IE6 users since they’re from the stone-age.”

      We all feel the IE6 pain, but do you not want to make money from potential customers just b/c they use IE6? I’ll accept their stone-age dollars any day of the week, and your clients will too.

      • http://www.measureddesigns.com Andrew Taylor

        Since going freelance a large percentage of my clients have IE6 as their primary browser, mostly due to having old email accounts like AOL. Unless there is a forced switch over (like analogue to digital for radio and tv in the UK), it will always be a case of educating them that it’s now 15yrs old and moving them onto something better.

        Unless your audience is 100% non IE6, a hacksheet to make things tolerable should still be on the checklist.

      • Mohamed Zahran

        You’re totally right ;)

  • http://thetechguia.wordpress.com Guilherme Vaz

    Great tut! Thanks!

  • http://www.jsxtech.com Jaspal Singh

    Nice CSS3 tips, thanks Brant for sharing this article.

  • ShadowAssassin

    That just looks disgusting hahaha – as some else said above, I hope no body would ever use something like this on real website.

    Good article though ;)

  • http://connorcrosby.me Connor Crosby

    Thanks for sharing, helpful!

  • Martin

    you know what i hate?

    i hate all these People who think: CSS3 is the best.
    but why? all of them using these code don’t understanding that most of the people doesn’t use Browsers who can interpret them.

    i mean where is the good part for me?
    all these buggy non-flash sites oder missinterpreted css3 rules.
    that makes me feel worry about all these developers who think to fast for the regular users..
    i’ve seen sites.. and i’ve seehn sites without css3+html5.. and it was an disaster.

    remember: there is ie6 still waiting. and all that other stuff i care about.
    and then there are people who cant use “transition:” because he have to use this rule with -moz, -o and whatever shit.

    i dont style border with -moz border or -o border or -webkit border.
    thats a shame and this is def. not in the way of thinking about standarts we have to regular and instinctiv thinking about standarts

    keep that in mind when the browser and css3 is ready to be well defined.

    • http://envexlabs.com Matt Vickers

      I stopped reading at “all these buggy non-flash sites” :P

      In all seriousness, I actually think your problem is with developers who use CSS3 techniques right now without having some sort of degrading fallback.

      Also, most sites that use a lot of HTML5 and CSS3 know that it won’t work in all browsers. 95% of them are just playgrounds, or experiments.

    • Mazz

      Thanks for showing your ignorance :)

    • Mads Kjaer

      I will not call you ignorant as some of the other repliers have, but I think you’re looking at it the wrong way.

      First and foremost, web design is NOT about making sure everything looks the same in every browser. Try reading a few articles on progressive enhancement and you will probably get my point. If you design for the lowest common denominator first (IE6 for most people) and then add enhancements like CSS3 effects, your users will be a lot better off.

      Secondly, if your HTML5/CSS3 sites break in older browsers, you’re doing it wrong. Either you have a fundamentally flawed understanding of how CSS, or you’re coding your sites the wrong way in the first place. Thousands of designers and developers are using these technologies with no or minor problems. I have developed multiple sites with HTML5 and CSS3 already, and I haven’t encountered a lot of problems that couldn’t be worked out with a bit of javascript and conditional comments. And if you’re marking up your pages in a semantic, accessible way, even a broken site will be of some use to the visitor.

      You mention that you are not willing to use the vendor-specific prefixes (-moz, -webkit and -o) because they are not “in the way of thinking about standards we have to”. I myself was a little confused about this in the beginning, but once you think about it, vendor-prefixes are perfectly aligned with what standards are all about. This article by Eric Meyer, who practically invented microformats and the CSS reset, explains everything perfectly: http://www.alistapart.com/articles/prefix-or-posthack/

      I honestly can’t take your comment seriously, but at least you now have some counter-arguments. It sounds like you don’t quite understand web standards yet – that’s okay – I am merely suggesting that you read a bit on the subject before calling CSS3 a “disaster” and the vendor-specific prefixes “shit”.

  • http://www.danielribeirogomes.com.br Daniel Ribeiro Gomes

    Great tutorial!

    Keep going!

    See ya!

  • Subeesh

    Is there any option to work fine in IE7?

    • http://www.snaver.net/ Snaver

      There is this new thing out: http://css3pie.com/ I’ve yet to use it, but it is a step in the right direction. The only problem i have with it is that there is seconds before the javascript kicks in where all your fancy elements are rendered ie-mode, which you can notice.

    • Brant
      Author

      For some things, Modernizr is worth looking at too. http://www.modernizr.com/

    • Mads Kjaer

      No, but the whole point of the article is that you should use these CSS attributes as enhancements. Ifthe browser doesn’t understand the CSS, there is no major impact on your site.

  • http://twitter.com/Site5Rebate Site5 Rebate

    CSS3 is really awesome, as is HTML5. The problem is, with so much of the Internet still using Windows XP and Internet Explorer 6 to access the web, it’s hard to make stuff that’s already “stable” work properly with full cross-browser compatibility.

    Microsoft is going to slow down dramatically the adoption of HTML5 and CSS3 unless they somehow forced a browser upgrade to Windows XP users. Too bad everyone doesn’t use Google Chrome… *sigh* Lord knows I’ve had plenty work in Chrome and then IE6 whines…

  • http://www.webcreationuk.com/ Bogdan

    Interesting reading, thanks for the share mate.

  • Danny

    i just skipped straight to the demo and saw that second nav and thought it was broken or something lol.

  • http://wwebz.com Rehaan

    Wow Great tutorial i always want to learn more on CS3 stuff. Net.tuts Please more CS3

    tHANKS :)

  • http://www.lifeintheroboticslab.com Pal

    Great set of icons, thanks for sharing. I have some icons I’d like to share tell me where is the best place to share them?

  • Martin

    there is no ignorance.

    i still care about standarts.
    i still care about better webdevelopment.

    css3 and html5 is fantastic!
    of course.

    but there are some people who aren’t care about the users, the way of coding in realistic dimensions.

  • http://www.isiservices.nl/ Asikur Rhaman Reko

    This is a great post and its also very impressive.
    thanks for share such type of good work….

  • http://mounir.tv sOLy MouniR

    Css3 Is very powerfull

  • http://www.jatinhariani.elementfx.com/photo_gallery Jatin Hariani

    CSS# is the best thing to have happened to the web.
    The effect on the form is jus plain awesome!!

  • http://www.jatinhariani.elementfx.com/photo_gallery Jatin Hariani

    CSS3 is the best thing to have happened to the web.
    The effect on the form is plain awesome!

  • http://laagsterentepersoonlijkelening.nl/ persoonlijke lening

    Hi. Neat article. There’s an issue with the web site in internet explorer, and you may want to check this… The browser is the marketplace chief and a huge section of people will pass over your great writing because of this problem.

  • http://www.clippingpathcenter.com/clipping-path-service.php mamun

    Amazing articles and its awesome..
    Thanks to share..

  • http://www.graphicexpertsonline.com/clippingpath.html mam_raj07

    Superb post and its really amazing..

    Thanks to share..