Archive for the ‘HTML/CSS’ Category

The great thing about HTML5 being open source

Monday, September 6th, 2010

I’ve said on here before that one of the things some developers might not like about HTML5 is that others can easily see the code of anything you make. But at the same time, for anyone trying to learn it’s as easy as right-click > view source. I love to take a look at code and figure out what does what and that’s one of the great benefits of technology like HTML5/CSS/JavaScript. It’s all there in the open, so if you see something that interests you, you can very easily take a peak.

I’ve seen some amazing things done with Flash and while I would love to know how they did it, you need a decompiler to take a look at the code and all the assets. Some decompilers will rename library items and variables so it’s a lot harder to figure out what does what. Plus, in some ways, I’ve always felt there was an ethical question when it comes to decompling .swf files.

I love going to a site, like Mr. Doob’s, and being able to see the code so easily. It might be one of the reason’s that I’ve spent so much time lately messing around with HTML5, CSS3 and JavaScript.

I recently reader Hackers: Heroes of the Computer Revolution and one of the main themes throughout the book was the Hacker Ethic, something that said make your hardware or software open source so that others could see what you’ve done and improve it which will make things better for everyone. If HTML5 takes off like it has the potential too, this idea will come back whether developers want it to or not.

Hopefully, developers out there take advantage of this and learn from what others have done. One of the things that gave Flash some bad press was developers making bloated and slow running programs. If a developer has the ability to look at someone else’s organized and efficent code, it might make them a better programmer and users will get better and smoother running programs.

Now if we can just get rid of the phases like “Runs best in Webkit” the future of the web is going to be wide open.

HTML5 games aren’t killing anything anytime soon

Thursday, August 26th, 2010

I came across the website HTML5games.com yesterday and there is some amazing stuff there. It’s one of those sites that makes you believe all the hype about HTML5. We’ll be making games that work for everyone without the need for a plug-in and it will all be open-source! This will all be true one day but I think we have a while yet. Why? A lot of the examples only work right in Safari or Chrome. It’s been a big enough challenge to get people to upgrade from Internet Explorer 6 to 7 and 8, and if IE9 doesn’t live up to it’s hype, I doubt enough people will move to Safari and Chrome to make HTML5 games a killer.

Also, take a look under the hood of some of these games. I’m amazed by the amount of JavaScript needed just to make something like Pong. I’ve said this before, but right not making HTML5 games is something that very experienced programmers are able to do. One of the things that made Flash great for making games is the actual Flash IDE. It’s pretty easy to get started with making a simple game because it only takes about 20 lines of code to create an object that you can control with the keyboard. Some of the examples I’ve seen take multiple JS files with a hundred lines of code each. The learning curve for HTML5 games is pretty high and I still think it’s going to take some kind of really kick ass IDE to allow beginners to start learning comfortably.

And I know there are developers out there that don’t want people to be able to take a look at their code and it’s as easy as right-click/view source to see how HTML5 games are made. And if you’ve spent weeks building a game for a company and then once you release it, anyone can come along and copy your code, it might be a reason for not wanting to make it using HTML5 and JavaScript. I realize this is all open source, but imagine how easy it would be to just copy and paste all the code and change the graphics a little bit.

I know this might come across as a “Flash guy” ranting but I’ve been spending a lot of time working with JavaScript and jQuery. I’ve never been a big fan of JavaScript but libraries like jQuery make it a lot easier to use. But I think for things like HTML5 games to take off, we’re going to need all the browsers to run JavaScript at the same speed and either an improved version of JS or an IDE that makes it easier to build them.

Quick and easy way to make cool buttons using CSS3

Monday, August 16th, 2010

Using some CSS3 and a bit of positioning, you can easily make good looking buttons for your web site. I’ve got two examples you can take a look at here. the first being buttons with a box-shadow.

1
2
3
4
5
6
7
8
9
10
11
.button {
   background:-moz-linear-gradient(-90deg, #273C4F, #205275);
   background:-webkit-gradient(linear, left top, left bottom, from(#273C4F), to(#205275));
   padding:10px 15px;
   -moz-border-radius:5px;
   -webkit-border-radius:5px;
   -moz-box-shadow:3px 3px 5px rgba(0,0,0,0.7);
   -webkit-box-shadow:3px 3px 5px rgba(0,0,0,0.7);
   position:relative;
   text-shadow:1px 1px 1px rgba(0,0,0,0.5);
}

We’ve got a gradient on the background and a box-shadow to give the button some depth. I’ve also added some padding so you can use this on an anchor tag and it will look good no matter what text you have. But what’s with the position:relative? That comes into play on the active state for the button.

1
2
3
4
5
6
.button:active {
   top:1px;
   left:1px;
   -moz-box-shadow:2px 2px 5px rgba(0,0,0,0.7);
   -webkit-box-shadow:2px 2px 5px rgba(0,0,0,0.7);
}

What happens here is that the when the button is clicked, it moves down and left one pixel and the shadow is decrease by one pixel to give it the effect of going down when it’s clicked on.

Now these look like hovering buttons but the same effect can be had on buttons you want to look like they’re going down into the background.

1
2
3
4
5
6
7
8
9
.button2 {
   background:-moz-linear-gradient(-90deg, #1987FF, #0055B2);
   background:-webkit-gradient(linear, left top, left bottom, from(#1987FF), to(#0055B2));
   padding:10px 15px;
   -moz-border-radius:5px;
   -webkit-border-radius:5px;
   position:relative;
   text-shadow:1px 1px 1px rgba(0,0,0,0.5);
}

Pretty much the same thing, but you’ll notice there’s no box-shadow. Now for the active state.

1
2
3
4
5
6
.button2:active {
   top:1px;
   left:1px;
   -moz-box-shadow:inset 2px 2px 5px rgba(0,0,0,0.7);
   -webkit-box-shadow:inset 2px 2px 5px rgba(0,0,0,0.7);
}

Now we add the box-shadow and set it to inset and it looks like the button is being pressed into the background. There’s one unexpected bug I came across with this one, the inset box-shadow doesn’t display right in Chrome on Windows, but it looks great in Firefox and in Safari. Why it doesn’t work in Chrome, I don’t know but hopefully, they’ll fix this bug quick, because I think this is a great looking effect that web designers have a real use for.

There’s HTML5 and then there’s HTML5

Monday, August 16th, 2010

I remember back in school, sometime in my second year, I read an article on A List Apart called A Preview of HTML5 and I was excited about the new tags, like <header> and <footer>. I was pretty sure <video> was going to make life a lot easier. But, really, that was it, it wasn’t a Flash killer or something to build amazing web apps, it was just a new version of HTML that would make my work a little easier. And over the last few years, I’d read articles about it and I was waiting for the day when I could start building sites using it. But then Apple changed everything.

We had a client talk to us about building them a new site and one of their questions was whether or not we knew how to build things using HTML5. It took me a minute, but I realized they didn’t mean HTML5 they way I thought about, they meant it the way Apple had been talking about it, as an all encompassing term that included CSS3 and JavaScript. And over the last six months this has pretty much become the norm, HTML5 means everything that you’d find in something like Apple’s HTML5 showcase or Google’s HTML5Rocks. Maybe it’s just me, but I don’t remember CSS3 transitions being a part of the HTML5 spec.

So it seems that HTML5 has become a term like Ajax, which stands for Asynchronous JavaScript and XML, even though it doesn’t have to include XML. Somebody just thought it sounded cool and started using it to reference a group of technologies that the name didn’t necessarily apply to. In the case of HTML5, it seems like it’s companies like Apple and Google that have spread the use of it as a name for a group of technologies that aren’t really under it’s umbrella.

But it seems that the web design and development community have accept this use and things like HTML5 apps, which use more than just HTML5 to work, are becoming widespread. I don’t have a problem with this but I just find it interesting that HTML5 has become an accepted buzz word so quickly and it’s acceptance is so widespread. And the next time a client brings up the term HTML5, I’ll know what they mean.

Move objects around the <canvas> using the keyboard and jQuery

Thursday, August 12th, 2010

One of the things that Flash is great at is making games and it’s one of the things that people are hyping the <canvas> tag being able to take over. Personally, I think it’s going to be a couple of years before that happens and one of the reasons is how much easier it is to build games using Flash. In fact, I was trying to figure out how to allow a user to move a block around a <canvas> using the arrow keys and I was getting pretty frustrated. Until I realized I could just use jQuery.

I’m not going to go through the whole thing because it’s just the next step from an earlier <canvas> post I did. But I’ll go over the changes and the great thing is, there isn’t too many. Plus, if you’ve ever made something similar in Flash, this will seem pretty familiar.

The HTML:

1
2
3
<body onload="init();">
<canvas id="canvas" width="500" height="400"></canvas>
</body>

Just setting the <canvas> height and width and setting the init() function to fire after the page loads.

The CSS:

1
2
3
4
5
canvas {
  display:block;
  margin:auto;
  border:1px dashed black;
}

Nothing interesting here, a dashed border so we can see the edges of the <canvas> and the margin: auto to center it.

The JavaScript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var context;
var rightKey = false;
var leftKey = false;
var upKey = false;
var downKey = false;
var block_x;
var block_y;
var block_h = 30;
var block_w = 30;

function init() {
  context = $('#canvas')[0].getContext('2d');
  WIDTH = $('#canvas').width();
  HEIGHT = $('#canvas').height();
  block_x = WIDTH / 2 - 15;
  block_y = HEIGHT /2 - 15;
  setInterval('draw()', 25);
}
function clearCanvas() {
  context.clearRect(0,0,WIDTH,HEIGHT);
}

function rect(x,y,w,h) {
  context.beginPath();
  context.rect(x,y,w,h);
  context.endPath();
}

function draw() {
  clearCanvas();
  if (rightKey) block_x += 5;
  else if (leftKey) block_x -= 5;
  if (upKey) block_y -= 5;
  else if (downKey) block_y += 5;
  if (block_x <= 0) block_x = 0;
  if ((block_x + block_w) >= WIDTH) block_x = WIDTH - block_w;
  if (block_y <= 0) block_y = 0;
  if ((block_y + block_h) >= HEIGHT) block_y = HEIGHT - block_h;
  context.fillRect(block_x,block_y,block_w,block_h);
}

function onKeyDown(evt) {
  if (evt.keyCode == 39) rightKey = true;
  else if (evt.keyCode == 37) leftKey = true;
  if (evt.keyCode == 38) upKey = true;
  else if (evt.keyCode == 40) downKey = true;
}

function onKeyUp(evt) {
  if (evt.keyCode == 39) rightKey = false;
  else if (evt.keyCode == 37) leftKey = false;
  if (evt.keyCode == 38) upKey = false;
  else if (evt.keyCode == 40) downKey = false;
}

$(document).keydown(onKeyDown);
$(document).keyup(onKeyUp);

So the first thing we do here is find the <canvas> using jQuery and get the height and width:

1
2
3
context = $('#canvas')[0].getContext('2d');
WIDTH = $('#canvas').width();
HEIGHT = $('#canvas').height();

And instead of drawing a ball and animating it bouncing, we use the arrow keys to move it around

1
2
3
4
5
6
7
8
9
10
11
12
function draw() {
  clearCanvas();
  if (rightKey) block_x += 5;
  else if (leftKey) block_x -= 5;
  if (upKey) block_y -= 5;
  else if (downKey) block_y += 5;
  if (block_x <= 0) block_x = 0;
  if ((block_x + block_w) >= WIDTH) block_x = WIDTH - block_w;
  if (block_y <= 0) block_y = 0;
  if ((block_y + block_h) >= HEIGHT) block_y = HEIGHT - block_h;
  context.fillRect(block_x,block_y,block_w,block_h);
}

If you’ve ever made a game with Flash or something similar, you should be able to see what’s going on here, we’re just saying, if the this key is pressed then move it this direction. Also, it checks to see if the block is at the edge, then don’t let it go any farther in that direction.

1
2
3
4
5
6
7
8
9
10
11
12
13
function onKeyDown(evt) {
  if (evt.keyCode == 39) rightKey = true;
  else if (evt.keyCode == 37) leftKey = true;
  if (evt.keyCode == 38) upKey = true;
  else if (evt.keyCode == 40) downKey = true;
}

function onKeyUp(evt) {
  if (evt.keyCode == 39) rightKey = false;
  else if (evt.keyCode == 37) leftKey = false;
  if (evt.keyCode == 38) upKey = false;
  else if (evt.keyCode == 40) downKey = false;
}

With these two functions, we’re just checking if the one of the arrow keys has been pressed, then we change the corresponding variable to true and it will move. Likewise, we then check to see if it’s been released and then the variable will become false and it will stop moving.

1
2
$(document).keydown(onKeyDown);
$(document).keyup(onKeyUp);

Finally, we use the jQuery events keydown() and keyup() to simplify the process of checking if one of the arrow keys are being pressed.

And here’s a demo of what we get.

It’s nothing amazing right now, but this is the first step towards developing a game using <canvas>. Hopefully, as the technology evolves, we get events and methods like AS3’s hitTest to make game development a lot easier. As I’ve said before, right now the <canvas> is fun to fool around with, but I think we’re still a few years and an pretty good IDE away from it being something the average developer can really work with.

I made my own HTML/CSS template and you should too

Wednesday, August 11th, 2010

In the last couple of days, a couple of HTML5 templates have been released, HTML5 Reset and HTML5 Boilerplate. I’ve looked them over and I have to say, especially in the case of HTML5 Boilerplate, they’re pretty solid. But they’re not for me. Why? Well, as soon as I looked at the index file, I went through it thinking “I’d take out that and that and that.” It’s the same reaction I had when I looked at the 960 Grid template and a few others. It’s nothing against them or people that use them, it’s just they’re not for me.

Why not? Over time I’ve just made my own. It’s pretty simple and lean and made for the way I build websites. I’m sure I could take someone else’s more comprehensive template and alter it to fit my needs, but I think that would be more work. I’d rather start from zero and build my way up than to edit one down to fit my needs.

This works for me because I’ve been doing this for a while and when it comes to coding HTML/CSS and even JavaScript or ActionScript, I’m fast and I think a template like HTML5 Boilerplate is just going to slow me down. Maybe if I put in the time to sit down and start using one of these on the next few sites I build, I’d get used to it and it might end up working for me. But I know that the way I do it now works and I’m comfortable with it.

I think every web designer/developer should build their own template. If you want to modify one that’s out there, but change it to fit your style. I’m a huge believer that everything should be about making coding comfortable, from the languages you use to the editor you work in and setting up a template is no different.

Animate a random bouncing ball with the <canvas> tag

Friday, August 6th, 2010

I’ve been experimenting with the <canvas> tag the last few days and from what I’ve seen, it’s got potential but it’s got a ways to go before we’re replacing Flash with it. But, in order to learn how to use it, I’ve been trying to reproduce things I can remember making when I was first learning Flash and ActionScript, and one of those things was a bouncing ball who’s movements where controlled through code.

To start off, here’s the HTML:

1
<canvas id="canvas" width="400" height="300"></canvas>

You have to assign the height and width of the <canvas> tag in the HTML because the default height is 150 pixels and the width is 300 and if you set the dimensions with CSS, the dimensions of the content inside the <canvas> will skew to the ratio of the CSS dimensions. For example, if you set the width to 600 pixels in the CSS and make a rectangle that’s 100 pixels wide, it will display at 200 pixels wide because you’ve double the width of the <canvas> with CSS. We also need to give the <canvas> an id of “canvas” so we can reference it with our JavaScript.

So for CSS, all I’ve included is this:

1
2
3
#canvas {
  border:1px dashed black;
}

It’s just there so that I can see the edges of the <canvas>.

JavaScript is what powers the <canvas> and to make this work, it takes about 35 lines of JS, not that much.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var canvasWidth = 400,
    canvasHeight = 300,
    ball_x = 5,
    ball_y = 44,
    ball_dx = 5,
    ball_dy = 5;
function init() {
  var canvas = document.getElementById('canvas');
  context = canvas.getContext('2d');
   
  setInterval('draw();', 25);
}
function clearCanvas() {
  context.clearRect(0,0,canvasWidth,canvasHeight);
}
function ball(x,y,r) {
  context.fillStyle = '#f00';
  context.beginPath();
  context.arc(x,y,r,0, Math.PI * 2, true);
  context.fill();
}
function draw() {

  clearCanvas();
 
  ball(ball_x, ball_y, 10);
 
  if (ball_x + ball_dx > canvasWidth || ball_x + ball_dx < 0) {
    ball_dx = -ball_dx;
  }
  if (ball_y + ball_dy > canvasHeight || ball_y + ball_dy < 0) {
    ball_dy = -ball_dy;
  }
 
  ball_x += ball_dx;
  ball_y += ball_dy;
}

So what are we doing here? Well, the first thing we do is define our variables:

1
2
3
4
5
6
var canvasWidth = 400,
    canvasHeight = 300,
    ball_x = 5,
    ball_y = 44,
    ball_dx = 5,
    ball_dy = 5;

Ball_x and ball_y are our ball’s initial position and ball_dx and ball_dy are the speed our ball will be travelling.

1
2
3
4
5
6
function init() {
  var canvas = document.getElementById('canvas');
  context = canvas.getContext('2d');
   
  setInterval('draw();', 25);
}

In our init() function, we use the getElementById to find our <canvas> and then we set the context to 2D because right now that’s all you can do, although, one day we’re supposed to be able to set the <canvas> to 3D. Next, setInterval is what we use to actually make the animation fire. It will called the function draw() and it will fire every 24 milliseconds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function draw() {

  clearCanvas();
 
  ball(ball_x, ball_y, 10);
 
  if (ball_x + ball_dx > canvasWidth || ball_x + ball_dx < 0) {
    ball_dx = -ball_dx;
  }
  if (ball_y + ball_dy > canvasHeight || ball_y + ball_dy < 0) {
    ball_dy = -ball_dy;
  }
 
  ball_x += ball_dx;
  ball_y += ball_dy;
}

What we’re doing in the draw() function is redrawing the ball every time the function is fired. In the if statements, we see if the ball has reached the edge of the <canvas> and if it has, we reverse it’s direction. To redraw the ball, we call the ball() function by passing in 3 values, the ball’s x and y positions and the ball’s radius.

1
2
3
4
5
6
function ball(x,y,r) {
  context.fillStyle = '#f00';
  context.beginPath();
  context.arc(x,y,r,0, Math.PI * 2, true);
  context.fill();
}

So when we pass in the new values, the ball() function will redraw the ball in it’s new position. The fillStyle sets the color to red and arc() sets the position, the radius, the starting point, Math.PI * 2 sets the arc to a full circle and then true or false sets clockwise or counter-clockwise.

In the draw() function, you might have noticed a function called clearCanvas() being called. One of the big differences between the <canvas> and the stage for Flash is that the <canvas> is actually redrawing itself every time the setInterval fires and it won’t remove the old ball position. So, in order to get the effect we’re looking for, we need to clear the <canvas> every time the ball moves.

1
2
3
function clearCanvas() {
  context.clearRect(0,0,canvasWidth,canvasHeight);
}

To do this, we call the clearRect() function where we set the position to 0,0 and set the width and height to width and height of the <canvas>. This way, we will clear the <canvas> every time we redraw the ball which will make it look like the ball is bouncing around. If we don’t do this, then the ball won’t be removed and eventually the entire <canvas> will fill up.

Finally to make the JavaScript run, we need to add this to the body tag:

1
<body onload="init();">

Now, after the page loads, it will run the init() function. You can also attact this to a button or a link if you want to start the animation that way.

Check out the demo.

So far, all the most complicated <canvas> examples I’ve seen have been done by hardcore programmers and are too complex to be something that people can realistically build for clients or even for fun. I think for <canvas> to really take off someone like Adobe is going to need to come out with an IDE that will do most of the heavy lifting for us. But for now, we can get started with things like this.

Be the Batman of web design

Tuesday, August 3rd, 2010

I’m a huge comic fan and as long as I can remember, Superman has been my favorite hero. But there’s a problem with Superman, he’s doesn’t make a very good role model. Why? Because Superman showed up on Earth and was immediately better than you at everything. That’s not really something you can aspire to unless, of course, you are planning on going to a planet where no one is as good as you at web design!

Batman is the one superhero that people can look to for inspiration because he’s one of the few that’s just a man. But in order to become Batman, he worked and worked until he became the best at all the things he needed to master to accomplish what he set out to. It’s been changed a bit over the years, but Batman became an expert at martial arts, an escape artist, a detective and a scientist. And, over the years, it’s become apparent that Batman will always be the last guy standing.

So what does this have to do with web design? Well, from what I’ve learned over the years, no one just shows up and is great at everything that it takes to be a great web designer. There are no Supermen out there, there are only people that have worked their way to becoming Batman. To be a web design Batman, you need to know design, HTML/CSS, JavaScript and technologies like Flash or PHP. And you need to be good at all of them.

Of course, not everyone can be Batman but trying to get there will make you better at what you do. Although, you could be like the Flash and be really, really good at one thing but I don’t think anyone is going to say the Flash is cooler than Batman.

CSS3 Transitions on Transforms in Firefox 4

Thursday, July 29th, 2010

In one of my previous posts, I showed how to use SVG as a mask over top of video and I based it on what I saw in a demo video showing off what Firefox 4 can do. With the release of the second Firefox 4 beta, Mozilla has released a few of the demos along with the code. The demo that I think has the most potential for real world use, is the London Project. I can see sites being animated like this really taking off, for better or for worse. And the great thing is, it only takes a few lines of CSS and one line of JavaScript to do it.

Here’s my version of what Paul Rouget made without the video.

How does it work? Like most CSS3 animations, it’s easy once you’ve figured it out. First off, the HTML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<body class="intro">
<div id="wrapper">
 <div id="intro" onclick="document.body.classList.remove('intro')">
    <h1><a href="#">WELCOME</a></h1>
    <p><a href="#">Click Here</a></p>
 </div>
 <div id="logo">
    <img src="demo_logo.png" />
 </div>
 <div id="picture">
    <img src="robot_slap.jpg" />
 </div>
 <div id="text">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tristique sem id tortor lacinia vel iaculis turpis tincidunt. Sed tincidunt venenatis neque, vel pretium dui suscipit id. Duis sit amet nibh quis ante pretium faucibus nec in quam. In feugiat rhoncus diam, id porta lorem blandit eget. Vivamus et velit sit amet nunc cursus pretium. Mauris in lectus nec tortor lacinia vehicula. Nam sed elit augue. Mauris id magna ipsum. Quisque sagittis aliquam elit at sagittis.</p>
 </div>
</div>
</body>

The only thing here that’s important to the animation is this line: <div id=”intro” onclick=”document.body.classList.remove(‘intro’)”>. This is what triggers the animation when the right box is clicked. It does this by removing the class “intro” that’s assigned to the body tag and then the elements of the page are animated to their new position on the page. Here’s the CSS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
body {
   margin:0; padding:0;
   background:#dabe25;
 font-family:Arial, sans-serif;
}
#wrapper {
   width:900px;
   height:500px;
   border:10px solid #000;
   margin:50px auto;
   -moz-border-radius:80px 0 80px 0;
 -webkit-border-radius:80px 0 80px 0;
   background:#fff;
   position:relative;
}
#intro {
 width:200px;
 height:100px;
 border:10px solid #000;
 text-align:center;
 position:absolute;
 left:350px;
 top:-200px;
 opacity:0;
}
#intro a {
 text-decoration:none;
 color:#000;
}
#intro h1 {
 margin:10px 0 0 0;
}
#logo {
 position:absolute;
 left:620px;
 top:15px;
 -moz-transition-duration:1s;
 -moz-transition-delay:1s;
}
#picture {
 width:500px;
 height:375px;
 border:10px solid black;
 position:absolute;
 top:60px;
 left:50px;
 -moz-transition-duration:1s;
 -moz-transition-delay:.5s;
}
#text {
 width:250px;
 padding:10px;
 border:10px solid #000;
 position:absolute;
 left:590px;
 top:130px;
 background:#ccc;
 -moz-transition-duration:1s;
 -moz-transition-delay:2s;
}
#text p {
 margin:0;
}
body.intro #intro {
 -moz-transform:translate(0, 380px);
 opacity:1;
}
body.intro #logo {
 -moz-transform:translate(0, -200px);
}
body.intro #picture {
 -moz-transform:translate(0, -800px);
}
body.intro #text {
 -moz-transform:translate(0, -800px);
}

Most of this is styling, which we don’t need to worry about here. We’ll look at just the #logo div because they all behave the same. If you look at the CSS for #logo, you’ll see its final positioning on the page. But there’s also body.intro #logo. Here, we’re using the transform property to animate the positioning of the #logo div. Using translate, we set the initial position to -200px which will take it off the viewable part of the page. And when the #intro div is clicked and the “intro” class is removed from the body tag, the #logo div is animated to its permanent position using the -moz-transition-duration property. All the different elements come in in a staggered effect using the -moz-transition-delay property.

And that’s it. Something that people will use Flash to get the same effect can now be done using just HTML, CSS and the tiniest amount of JavaScript. Right now this only works in Firefox 4, but it’s designed to display properly in all other browsers, just without the animation or, in some cases, the rounded corners.

Poke around in the demo and look at the Mozilla one, which adds SVG masks to the mix. Getting on board with techniques like this as early as possible is going to be the right move, especially since HTML5 is the latest buzzword clients are bringing up when talking about websites. And I’m a fan of adding in extra things like this for people that use newer browsers, as long as it still displays properly in older ones.

In some browsers <textarea> is resizable

Sunday, July 25th, 2010

I was building a contact form a few weeks ago and since I use Firefox 3.6 to do my testing while I build a site, I didn’t noticed until I checked the site in Chrome that you can now resize text areas. If there’s a couple of diagonal lines in the bottom right corner of the text area, you can click and drag to resize it. Checking around, I’ve found this is only available in Chrome, Safari and Firefox 4 right now, but I’m sure that when Internet Explorer 9 comes out, it will be there too. Is this a big deal? Maybe not, but when you resize the text area if can affect the design around it, moving text and pictures around. And I know from experience, that’s the kind of thing that can become a major issue for some of the clients I’ve worked it, if they happened to discover you can do that.

But this is an easy problem to solve. I usually set the height and width of form elements in my CSS. But there’s a couple of tricky things you should know. If you just set this:

1
2
3
4
textarea {
  width:400px;
  height:300px;
}

It will set the height and width of the text area but it will let the visitor make it bigger although not smaller. You have to set the max-height and max-width as well. If you just set the max-height or max-width, the visitor can resize the text area from the default width to the max-width you’ve set and the same with height. So both need to be set in order to prevent any resizing:

1
2
3
4
5
6
textarea {
  width:400px;
  height:300px;
  max-width:400px;
  max-height:300px;
}

So far, I haven’t been able to find any info on preventing resizing with a setting inside the actual HTML tag, but since CSS is used nearly 100% time, it’s not a big deal to do it this way.