Finishing Touch

The overuse of HTML5 and CSS3

Click the image to view the demo

As I’m getting more familiar with all the aspects of designing for the web I constantly bump into small unimportant problems. In most cases those problems can be solved with some CSS trickery or javascript. One way or the other I always find some sort of solution that works out pretty fine, up till now.

The challenge

A few weeks ago I designed some category tags with a slightly odd shape for a WordPress blog. Normally I would slice up a PSD-file in different parts and use them as background images to style those kind of tags. For this blog I figured it would be a nice touch to fully style the tags in CSS3. I came to this idea after reading an article on how CSS3 can be used to create different kind of shapes. Because the shape of the tags I designed was pretty basic, I thought it was perfectly possible to design the whole thing in CSS3.

The tags I designed in Photoshop consisted of 7 styling elements:

  1. Round corners
  2. Gradient fill
  3. 1 px solid border
  4. Uppercase text
  5. Lighter hue text shadow to create depth
  6. A triangular extension
  7. A tiny hole with border

The first 5 elements are very easy to do. The triangular extension and the tiny hole in the middle on the other hand are a bit of a challenge. The triangle can be made with transparent borders and the hole can be seen as a tiny square with nothing but rounded corners.

Execution

For an overview of all the techniques used for this article take a look at the demo page I made. From top to bottom you’ll find the same tags designed in Photoshop, with CSS background-image property, CSS3 and HTML5.

Live Demo

First try: CSS3 transparent borders

For this exercise I based my coding on an excellent tutorial written by Alan Grakaric. Alan makes use of the CSS selectors “:after” and “:before” to keep the amount of HTML elements as low as possible.

<ul id="css3">
	<li><a href="#">Photoshop mockup</a></li>
	<li><a href="#">CSS background-image</a></li>
	<li><a href="#">CSS3 border-radius</a></li>
	<li><a href="#">CSS3 transparent borders</a></li>
	<li><a href="#">HTML5 Canvas</a></li>
</ul>

The left triangle in the tag is going to be a challenge. As mentioned the technique Alan Grakaric used, involves transparent borders. The trick is to add thick borders to an empty element. All borders will look like a triangle because that’s how the box-model is designed. If you make all but one border transparent you end up with a triangle.

ul#css3 a:before{
	content:""; /* Empty element */
	float:left;
	position:absolute;
	top:0;
	left:-8px;
	border-color:transparent #c9e5f5 transparent transparent;
	border-style:solid;
	border-width:12px 8px 12px 0; /* 24px high, 8px wide */
	}

For the rest of the styling I used a gradient fill for the background and border-radius for the rounded corners. You can take a look the source code for more details. The final version looks like this:

As you can see all of that CSS3 styling is doing a pretty good job in general but it’s lacking something. The transparent border trick worked to make a triangular extension but it is impossible to add an extra border to that triangle. So the triangle trick is quite ingenious, but it doesn’t solve the real problem. It’s still impossible to really change the shape of an HTML element with CSS.

Second try: HTML5 canvas

Now that we’re exploring new grounds we can just try HTML5 as well. One of the new elements W3C introduced together with HTML5 is the Canvas element. This element allows us to draw any kind of shape directly into an HTML file. Essentially it’s just another HTML element such as a div or a span in which something can be drawn with javascript. It goes something like this:

			window.addEventListener('load', function () {

// Get the canvas element.
			var can1 = document.getElementById('canvas1');
			var context = can1.getContext('2d');

// Define how the shape should be filled
  			var lingrad = context.createLinearGradient(0,0,0,25); //create variable with linear gradient from top to bottom
  			lingrad.addColorStop(0, '#c9e5f5'); //set top color
  			lingrad.addColorStop(1, '#aed8f0'); //set bottom color
			context.fillStyle = lingrad; // set fillstyle to variable "lingrad"

// Define how stroke should look like
			context.strokeStyle = '#86bedf'; //stroke color
			context.lineWidth = 1; //stroke width

// Create tag shape
			context.beginPath(); // Let's start drawing our shape.
			context.moveTo(0.5, 12); // Where to start drawing.
			context.lineTo(8.5, 0.5); // Draw top diagonal side of arrow
			context.lineTo(161.5, 0.5); // Draw top side of shape
			context.quadraticCurveTo(164.5, 0.5, 164.5, 3.5); // Draw the top right rounded corner
			context.lineTo(164.5, 20.5); // Draw right side of shape
			context.quadraticCurveTo(164.5, 23.5, 161.5, 23.5); // Draw the bottom right rounded corner
			context.lineTo(8.5, 23.5); // Draw the bottom side of the shape
			context.lineTo(0.5, 12); // Draw the bottom diagonal side of arrow
			context.closePath();// Stop drawing that tag shape

			context.fill(); // Fill the shape as defined above
			context.stroke(); // Add a stroke to the shape as defined above

// Add little white hole in tag
			context.fillStyle = "white"; // Set filling color to white
			context.beginPath(); // Start drawing circle shape
			context.arc(12,12,3,0,Math.PI*2,true); // Circle with 3px radius
			context.closePath();// Stop drawing that tag shape
			context.fill(); // Fill the hole as defined above
			context.stroke(); // Add a stroke to the hole as defined above

			}, false);

I was really amazed with the sort of freedom you get when you design with this technique. You can give exact dimensions to the shape, add a gradient fill, add a border and so on. On the other hand, the freedom of drawing exact shapes is also a shortcoming since the dimensions of each drawing are fixed. If you add dynamic content to the canvas, such as a dynamically created text, it will not resize according to its content. This clearly shows in the rendering at the demo page or in the screenshot below.

I don’t want to discard this technique as something incomplete because I’m sure there’s a way to change the width of each tag with an extra piece of javascript code. But as a novice I’m not (yet) capable to craft something like that. For now I think it’s fair to say that HTML5 canvases are not designed for this sort of tasks.

Final try: good ol’ background-image

So there I was, almost a full day had past and I still had nothing functional. At that point I knew I had to fall back to the good old background-image property. It’s very easy to implement, works like a charm, works on every browser and is still pretty lightweight.

As you can see in the image above, the end result is a perfect copy of the Photoshop mockup. All of the elements are there, the width of the tags changes according to its content and all it took was a few lines of code.

Conclusion

Today I learned a lesson in efficiency. Sometimes you neglect the easiest things when you are getting too ambitious. New technologies are invented for a reason and if you don’t have a clear understanding of that reason, you end up making it yourself too complicated. Lately, the use of CSS3 and HTML5 is booming in the web design sector. For almost each task, designers find some way or another to implement CSS3 or HTML5 because it’s the latest thing. Sometimes it’s overlooked that older proven techniques are just better for the job than the new fancy stuff.

Although I see a ton of possibilities with some of the HTML5 specification for the future, I believe CSS3 is taking us in the wrong direction. Or better, I believe designers all over the world are using CSS3 for the wrong reasons. One of the biggest limitations of CSS3 is that it’s still impossible to really change the shape of an HTML element. And that is quite frustrating because that’s exactly what designers want. They want full control over the look and feel of their websites. So they end up using little hacks and tricks to mimic what they want.

I strongly believe that we’re getting there step by step. Canvas drawing allows us to create any shape we want. We can now fully control the way shapes looks, how they’re oriented, which size they have and so on. The only problem is that a good understanding of javascript is needed to complete the more difficult tasks. Until now web designers were pretty spoiled with the limited designing options they had. In the future they’ll have to start learning to code whether they like it or not. I believe this will cause a great shift in how websites will be built in the future. Chances are that a lot of the upcoming web designers will grab to WYSIWYG applications that will do all of the coding in the background. This might create a bigger gap between coders and designer then there ever was before.

What do you think? Will technologies like HTML5 bring designers closer to coders or will it drift them further away from each other?

A clean calendar in CSS3 & jQuery

Click the image to view the demo

Almost a year ago I had the idea to build a calendar app. The project was called LiveCal and was supposed to become a platform where you could share calendars. The whole idea was that calendars would become something you subscribe to. Let me clarify. Let’s say you are subscribed to the calendar stream of your school. One of your teachers plans an event, such as a task or a test and adds it to the calendar stream. From the moment the event is added to the stream, you’ll get a instant notification that a new event is being planned. This means you’ll always walk around with an updated calendar. Due to the complexity of the idea and the lack of knowledge on my side this project never really took off.

Nevertheless I started to make a CSS3 calendar with some jQuery animation while I was working on this project. In this article I will explain, step by step, how to use the calendar.

How to get it

You can download or view a demo of the animated CSS3 calendar by clicking one of following links.

Download    Live Demo

How to use it

You’re allowed to use the calendar for your own purpose. For those who are interested to learn a bit more about how the calendar is built, I made a short guide about the animated CSS3 calendar.

Basic HTML structure

The first thing we have to do is add structure to the HTML file. To keep things as simple as possible I used the usual terms you find in a calendar. A day is nested in a week and a week is nested in a month. The div that represents a day is divided in three subdivs:

  • daybar: the top bar displaying the day’s number of the month
  • dots: a div containing an unordered list to present dots according to the events of that day.
  • open: a div containing all events of that day. This div is only visible if it’s slid out.
<div class="week">
    <div class="day">
        <div class="daybar">
            <p>31</p>
        </div>
        <div class="dots">
           <ul>
               <li></li>
           </ul>
        </div>
        <!-- slide open -->
        <div class="open">
           <ul>
               <li></li>
           </ul>
        </div>
        <!-- slide closed -->
    </div>
</div>

At the end of this article you can find out how I used jQuery to animate the accordion style calendar.

CSS Styling

There are three styling elements that are important in the calendar.

  • Color: add color to the dots and the events
  • Length: add length to the events. A one hour event should be half the size of a two hour event
  • Padding: Position each event on the right spot.

Colors

For this calendar I made four classes with color names. If you add one of the classes to any div then that div will obtain the background color of that class. For example, if you want to create a green dot, you add the class “green” to the list element.

<div class="dots">
    <ul>
        <li class="red"></li>
        <li class="green"></li>
        <li class="yellow"></li>
        <li class="blue"></li>
    </ul>
</div>
  • Red
  • Green
  • Yellow
  • Blue

This calendar makes use of 4 different colors. Of course you can add as many colors as you want.

Event length

Instead of giving each individual event a specific height or length, I made some pre formatted classes you can use. Just type “lxx” where x is the amount of hours you want the event to be.

  • l1 = 1 hour event
  • l5 = 5 hour event

For example:

<div class="open">
    <ul>
        <li class="yellow l2"><p>2 hour event</p></li>
        <li class="green l10"><p>10 hour event</p></li>
    </ul>
</div>

Event padding

We now managed to add color and length to the events. To position each event on the row according to the start of the event, we need to add an extra class to each div. I made a preformatted class “ax” where x stands for the amount of hours between the previous event or the beginning of the day if no event took place.

  • a1 = after 1 hour. The event starts at 1 o’clock
  • a12 = after 12 hours. The event starts at 12 o’clock
  • Multiple events
    • a8 = after 8 hours. The first event starts at 8 o’clock
    • a4 = after 4 hours. The second events starts 4 hours after the previous event, which is at 12 o’clock

For example:

<div class="open">
    <ul>
        <li class="yellow l1 a13"><p>13:00 first event</p></li>
        <li class="yellow l1 a1"><p>15:00 second event</p></li>
        <li class="red l2 a3"><p>19:00 third event</p></li>
    </ul>
</div>

Keep in mind you’ll have to take the length of the event into account when you are adding spacing above an event.

jQuery magic

For the accordion effect used in this calendar I made a customized script based on the Simple jQuery Accordion menu. I tried to simplify the Simple jQuery Accordion script resulting in fewer lines of code. Here is my version.

function initMenu() {
//create variable named "block" and put class ".day" in it
	var block = $(".day");
//hide every div with class "open"
	$('.open').hide();
//when a div with class ".day" is clicked ...
	block.click(
		function() {
//... find all divs with class "open" and slide them open
			$(this).parents('div:eq(0)').find('.open').slideToggle('fast');
		}
	);}
$(document).ready(function() {initMenu();});

Put this piece of code in the header of your HTML file and you should be ready to go!

Questions?

As I’m no longer using this calendar for the project I thought it could be useful for someone else. I hope my instructions are clear enough for you to figure out how to use it. If you have any problems with the calendar, feel free to ask questions. I’ll try to answer as quickly as possible.

Is Ren Ng the new Steve Jobs?

© Stanford University

Some of you might not have noticed it, but photography, as you know it, is about to change completely. One man is stirring up the whole camera market with his latest invention, the Lytro Light Field Camera. This new type of camera makes it possible to snap a picture and refocus it later. This means no more blurry photos of someone standing too close or too far away from the camera.

The man who is crazy enough to accept this challenge is Ren Ng, the founder and CEO of Lytro. He was born in Malaysia and immigrated to Australia at the age of 9. In his pursuit to fulfill his dream of becoming a professor, he graduated at Stanford University. While he was doing his PhD research on digital light field photography, he came to realize his inventions had a lot of potential. So he put his dream of becoming a professor on hold and started his own company called Lytro. As I was reading about Ren Ng I found there were a lot of similarities with someone else in the technology industry. Who else would be crazy enough to try and change an already mature and established market? The only name I could come up with was Steve Jobs.

Similar ideas

Since Steve Jobs passed away, people are looking for the next charismatic world changer. Although I believe Ren Ng is definitely not that person, I want to point what a great visionary he is by comparing some of the things he did, with some parts of Steve Jobs’ career.

Steve Jobs, showing an iPod nano. Ren Ng, showing the Lytro Light Field Camera

© PCmag

1. Ambitious visionairies

Just like how Steve Jobs jumped in the computer market as a college dropout, Ren Ng had to take a huge step to go from being a researcher to become a CEO. He suddenly had to work his way around in a completely new environment of entrepreneurship. As an outsider it is hard to find out how he managed to go through this transformation so well. It’s possible that just like Steve Jobs, he has a great intuitive way of organizing himself. For what we can see now is that he surrounded himself with very competent and intelligent people and that is one of the indicators that he has what it takes to become a great CEO. If you have the guts, the ambition and the vision to come up with a brand new idea and transform it into a viable attractive product then you know there is a great career waiting for you.

2. Tackling myths

I don’t know if you noticed it but some details about the Lytro camera are formulated differently compared to what the standard is nowadays. The word (mega-) pixel is nowhere to be found on their website. This is a clear signal to me that they want to tackle the megapixel myth. The amount of megapixels you camera sensor has, doesn’t tribute to a better camera output. It’s all about how the information that is contained in a ray of light can be successfully transformed into an array of digital bits. That’s probably one of the reasons why Ren Ng chose to use the term “Megarays” when he talks about camera resolution. This takes me back to July 2001 when Steve Jobs explained “the Megahertz Myth” in his keynote about the new PowerPC G4-processor.

One of the other things that struck my mind is how both Steve and Ren dared to take the risk to come out with a product that looks completely different from what was popular at that moment. The original Macintosh and later on the first iMacs were out of this world. No other computer manufacturer tried to make a computer as compact and complete as the original Macintosh. It’s that kind of innovative and ambitious move that Ren Ng is taking with the new Lytro camera. Not only did the technology inside drastically change, they also put a lot of effort in redesigning the standard camera form factor. For more then 50 years the general shape of popular cameras haven’t really changed. They just got smaller, lighter and thinner but essentially they kept there original shape, uptill now.

3. Good sense of design

Steve jobs is known for his great sense of aesthetics. Recently it came to light that he left Jonathan Ive, the lead designer for Apple’s products, more control over the design proces. It takes a lot of trust and confidence to take such decisions. We know that choosing the right people for the right job is what made Steve Jobs so successful. And that is exactly what Ren Ng is doing with Lytro. He’s taking young, enthusiastic and clever people and lets them do what they do best. This, for example, led to the beautiful innovative design of the Lytro light field camera.

Blue Lytro camera

© Lytro

Different backgrounds

As many similarities you can find between these two innovators, you’ll find many differences. Ren Ng for example, is basically following the rules. He is the perfect example of an ideal son who was never involved in criminal activities and always scored high grades. He recently finished his PhD and was awarded for the best PhD dissertation at Stanford University. This attracted a lot of investors, which eventually led to birth of a new technology company called Lytro. His succes story in no way compares to the path Steve Jobs took. Most of his life he was an outsider, in conflict with everyone including himself. He had to go through psychological and spiritual changes to become the person we know. He always found a way to bend the rules for his own good even if someone had to be sacrificed. This shows that, though on a professional base a lot of similarities can be found, most of their history was completely different. For that reason I believe it is meaningless to try and find similarities between their personalities.

To early to tell

To answer to the question if Ren Ng is the new Steve Jobs, I have to say it’s impossible to tell. There’s no way to find out if Ren Ng is going to be a world changer because he still has a lot to prove. All we can say at this moment is that he’s got a lot of potential. Most of his decisions are spot on and I expect a lot of him in the future. All I hope is that he’ll never lose his ambitious drive to invent new technologies and that he will continue to surprise us with new, crazy, revolutionary products.

Do you think Ren Ng could be become a world changer?

Greetings

Dear web community. Today I’m launching a blog where I’ll be sharing my latest thoughts and ideas. For a long time I have been running around with the idea to start a blog. But someway or another I could never make the time to do so. Let this post be a very first step in that process. Before I start blogging I want to tell you why I’m doing this.

There are 4 reasons why I want to blog.

  1. Improve my english
  2. Improve my writing skills
  3. Force myself to be stop procrastinating
  4. Share thoughts and ideas

1. Improve my english

Being a Belgian citizen I’m supposed to know 3 different languages and English isn’t one of them. Up till now my English is based on autodidactic learning through watching American television shows and movies. To be honest I was taught some basic grammar and vocabulary in high school but until now I never really had to speak or write English anymore. In a globalizing world I realize the importance of communicating using an international language and therefore I need to improve my English.

2. Improve my writing skills

The last decade of my life, I was studying natural sciences with Biology in particular. So all of my writing in the past six years was limited to the use of specific terminology. Now I realize my creative writing skills have deterioriated and the only thing I can do about it is, practice. I need to expand my vocabulary and improve my grammar to make sure I’ll be able to write some decent articles in the future. I believe that when I continue to blog, I will have to put a lot of effort into my texts and eventually my writing will improve.

3. Force myself to stop procrastinating

I have a confession to make. I’m a procrastinator. I like to plan a lot things and I’m mostly filled with a lot of big ideas but I never really finish one of them. A few months ago I decided for myself that I needed to stop postponing everything. It’s just too easy to come up with excuses. If I want to fulfill some of my dreams I need to start acting and start acting right now. Putting a blog online for everyone to see, I’ll be forced to maintain this website. I hope this will encourage me to start and finish some of my future plans.

4. Share thoughts and ideas

The last and most important purpose of this blog is that I want to share my ideas and thoughts with the world. Through the years I came to realize that most of the media I’m using are not suited to do this sort of things. I like to keep social media for things I want to share about my personal life and therefore websites like Facebook are not the ideal platform to do this. Twitter on the other hand is perfect because it connects you with hundreds, not thousands of people who share the same interests or ideas. But their character limitation makes it impossible to write everything down and it will definitely not improve my writing skills. For that reason I think a weblog is the perfect medium to share my thoughts and ideas.