BlueFlux Graphic Design

BlueFlux Graphic Design
My Home

Saturday, 7 April 2012

Choose Carefully! Not All Browsers Are Up to Date



Recently I've been trying out some of the new HTML5/CSS methods.
However, I've noticed that not all of the most popular browsers have implemented the latest technologies.
Applying some of the new styles may keep your web page up to date, but be careful and check that your new page works on every browser.
One of the most frequently used objects on your page will be buttons, the obvious way to navigate around your site.
Creating a smart and eye pleasing button, or a whole row of buttons for navigation adds to the whole look of the theme you've decided on for your web page.
A lot of people use their mobile devices for casual browsing of the internet, so using the new techniques instead of using images can be the difference between fast download times and a impatient user redirecting and trying another site.
The same goes with using page or menu gradients without the use for images to achieve the same effect.
So, if your building your own site, check your CSS against as many browsers as possible or you could be publishing content that isn't being seen the way you intended.

Martin


Friday, 6 April 2012

Drawing A Button HTML5 and CSS3 - No Images Used

Save on download times for your websites and blogs.


Below is a relatively tidy button rendered through your browser using only HTML (no images).
If you consider how many buttons and menus you may need to use for your web page, it can all add up to a lot of bandwidth savings.





Here's the HTML:
nb: if you are seeing a faint border around the button, this has been applied by  blogger and not part of the HTML posted below.

These styles are all applied using inline css, if you want to apply them using a css file just use the following syntax:

<style type="text/css">
#hLight{
height: 52px;
position: absolute;
left:116px;
top: 82px;width: 101px;
z-index: 2;
border-radius: 3px;
-moz-border-radius: 3px; 
-webkit-border-radius: 3px;
-o-border-radius: 3px;
-ms-border-radius: 3px;
 box-shadow: 0px 0px 3px 2px #a3a3a3 inset;
-moz-box-shadow: 0px 0px 3px 2px #a3a3a3 inset;  /*firefox*/
-webkit-box-shadow: 0px 0px 3px 2px #a3a3a3 inset;  /*Chrome and Safari*/
-o-box-shadow: 0px 0px 3px 2px #a3a3a3 inset;  /*Opera*/
-ms-box-shadow: 0px 0px 3px 2px #a3a3a3 inset;  /*Internet Explorer 10*/
}
#buttonHL{
position: absolute;
top: 0px;
left: -1px;
width:100px;
height:50px;
z-index:3;
opacity:0.5;
-moz-opacity: 0.5;
filter: alpha(opacity=50);
}
#buttonHLTxt{
font-size: 16px;
font-weight: bold;
left: 28px;
position: absolute;
top: 15px;
z-index: 4;
width:20px;
height:50%;
}
#buttonHighlight{
position: absolute;
left: 115px;
top: 81px;
width: 99px;
height: 50px;
background-color: red;
border: 2px solid #000000;
box-shadow: 0px 0px 3px 3px #333333;
-moz-box-shadow: 0px 0px 3px 3px #333333;
-webkit-box-shadow: 0px 0px 3px 3px #333333;
-o-box-shadow: 0px 0px 3px 3px #333333;
-ms-box-shadow: 0px 0px 3px 3px #333333;;
z-index: 1;
}
</style>

<body>
<div id="hLight">
<div id="buttonHLTxt">
<div align="left">
<a href="http://www.w3schools.com/html5/default.asp" style="color: black;" target="_blank">HTML</a>
</div>
</div>
</div>


<div id="buttonHighlight">
<canvas id="buttonHL"></canvas>
</div>


/*javascript for creating a fill gradient ( using HTML5 )*/

<script type="text/javascript">
<!--button highlight-->


var b=document.getElementById("buttonHL");


var btx=b.getContext("2d");


var brd=btx.createLinearGradient(0,0,0,40);


brd.addColorStop(0,"#000000");


brd.addColorStop(1,"#FFFFFF");


btx.fillStyle=brd;


btx.fillRect(00,00,100,50);
</script></div>
</div>
</body>


This button has been drawn using the HTML5 gradient fill method. Unfortunately, there seems to be no support as yet, for rounding corners of the canvas.
So, I have used another div and applied an inset box-shadow to make it look like the corners are rounded.
However, there is some support for rounding the canvas corners when using the SVG gradient method.
This will be my next post.


For a more detailed look go to http://www.blueflux.eu/HTML5.html


This post was written as all the new methods were being released. Since then I have cleaned up the html to make it easier for anyone reading this to understand, and copy and paste the code into their own HTML editor to experiment with themselves.

There is also more support for CSS3 in most of the modern browsers available.
Instead of using the HTML5 Gradient, you can use CSS to do it instead, below is an example of a gradient fill:

( Support for this technique is still limited for example on IE9 and Opera and using HTML5 instead seems to have more support within all the browsers rather than using css. )


This will apply a gradient from one colour to another, starting at the top, and will be blended in half way down the height of the div( or canvas ) to the second colour:#FFFFFF.

#buttonHL{
position: absolute;
top: 0px;
left: -1px;
width:100px;
height:50px;
opacity:0.5;
-moz-opacity: 0.5;
filter: alpha(opacity=50)
background: linear-gradient(top, #AA8800, #FFFFFF 50%);
-moz-background: linear-gradient(top, #AA8800, #FFFFFF 50%);
-webkit-background: linear-gradient(top, #AA8800, #FFFFFF 50%);
-o-background: linear-gradient(top, #AA8800, #FFFFFF 50%);
-ms-background: linear-gradient(top, #AA8800, #FFFFFF 50%);
}



This will create a gradient that has another colour  blending into and out of the centre of the div


background: linear-gradient(top,  #AA8800,  #FFFFFF 54%,  #AA8800 10%,#AA8800);
-moz-background: linear-gradient(top,  #AA8800,  #FFFFFF 54%,  #AA8800 10%,#AA8800);
-webkit-background: linear-gradient(top,  #AA8800,  #FFFFFF 54%,  #AA8800 10%,#AA8800);
-o-background: linear-gradient(top,  #AA8800,  #FFFFFF 54%,  #AA8800 10%,#AA8800);
-ms-background: linear-gradient(top,  #AA8800,  #FFFFFF 54%,  #AA8800 10%,#AA8800);

***This is supported in all but Internet Explorer 9 and below and a few mobile browsers like Dolphin HD for Android.***


There is now greater support for the border-radius property:

border-radius:1em;/2px;

But again, support isn't 100% so you'll have to do the same as me and many other developers and make up your own mind on how to design your site and the best techniques to use to cover the wide variety of browsers that people use today.



Thursday, 5 April 2012

Using 'Canvas' For Drawing Buttons, Images & Text - The Reasons Behind The New HTML Standards And The Welcome Introduction Of CSS3

HTML5 Canvas - fillText
CSS Background Gradient
Scaling an Image using drawImage


With the growth of the internet, more mobile devices and the increased amount of traffic, there are some new methods such as css3 and HTML5 which can be used to minimise the amount of requests sent by the users' browser.

This, in turn, reduces the amount of information needed to be sent over both phone lines and mobile networks and increases the amount of work done by the users' computer.

Less requests for things like images also reduces the time needed to download a web page, most noticeably when the user is downloading using their networks' data connection.

Let's say, for example, you have a website that has been branded and you have the same logo more than once on either a single page or every page.
Once the logo image has been downloaded on the first visit, any subsequent visit to another page can have the image placed by using the HTML 'drawImage' method. That's one less request!

You can see this in action here CWC. The original image has been requested, downloaded and placed in the top right corner.




But I've also used the image in the header of the price list and scaled it down to fit. Without the new HTML5 I would've had to use a separate image that has been scaled down using my imaging software.




Now, I know that you might think that I can just place the image as is, and then adjust the size of the image properties using my html editor. This is ok but the images rarely get scaled down properly and you lose the original quality.

All this adds up to less traffic to and from one user, less data usage for mobiles and leaves more bandwidth for other users as more and more people get connected to the internet.

I'll give an example of something I'm sure most people have, or will have, experienced on one New Years' Eve.
Do you remember sending a text message wishing your friends or family a happy new year?
Did you notice that it seemed to take a long time to deliver, or that you received one several hours after midnight?
It's all based on the computer and the software used to send out those messages. If you send a text, somewhere along the line it will be placed in a queue.
If there's only ten in that queue, you probably wouldn't have noticed the delay even if you were at the bottom of that queue.
Now imagine the same thing but with a queue that's suddenly grown enormously due the amount of people sending a message at midnight. Obviously you'll have a quite a while to wait if you're near the bottom.

Now apply this example to the amount of requests to a server, the less requests sent the smaller the queue and the faster yours and everyone elses requests get dealt with.

Using a lot of images is one of the obvious file size concerns when designing a website. So using gradients, drawing a few shapes and possibly drawing some text can save on webpage download time and bandwidth.

Below is an example of using a canvas and drawImage to redraw the logo:

I'll assume that you already have your web page set up and open for editing, so the first thing you need to do is insert a the canvas on to the page where you're going to draw the image.

As I said, mine is getting placed at the top of the price list. If you're using an old version of Dreamweaver like I am, you can just insert an Ap Div and then type in 'canvas' in place of 'div:

<div id="logo"></div> will become:-

<canvas id="logo"></canvas>

Then you need to insert the code to draw the image inside your canvas:

<script type = "text/javascript">
var c.getElementById("logo");
var ctx = c.getContext("2d");
var image = new Image();
img.onload = function(){
ctx.drawImage (img, 0, 0, 320, 150);  /* values are: x, y, width, height*/
};
img.src = "../images/myLogo.png";
</script>

If you're placing more than on instance, don't forget to use different variable and function names for each one.

I've created a page as a test using HTML5, the latest css and some jquery.

Take a look at the source code (http://www.blueflux.eu/HTML5.html) to see the different technique needed for drawing within the same canvas, and the problems that arise by using this technique. Such as the conflict between fill styles and the inability to apply rounded corners to any svg/HTML5 type gradients...(currently,working with IE9 and Opera )

**Some of the syntax has changed recently for things like gradients with css and I'll be updating the HTML5 page very soon.** 

I've also used some of the new css techniques, some of which don't yet work in all of the most popular browsers. However they all currently work in the latest Firefox and Chrome browsers

For a nice gradient as a background image I've had to use a very large image up to, and over 2000 pixels wide to cover wide screens as well.
Now you can use css to do it. The following example will create a gradient background from black to white starting from the top of the page: ( gradients not supported in IE9- )

#bkgnd{

background-image: linear-gradient(top, #000 35%, #fff);
background-image:-moz- linear-gradient(top, #000 35%, #fff); /*Firefox*/

background-image:-webkit- linear-gradient(top, #000 35%, #fff);/*Chrome and Safari*/

background-image:-o-linear-gradient(top, #000 35%, #fff);/*Opera*/
background-image:-ms-linear-gradient(top, #000 35%, #fff);/*Internet Explorer 10*/

}

One thing I like to use when designing a site is the use of drop shadows. This adds some depth and texture to any page.
By using the css box-shadow method to add drop shadows to images and layers, you can use an image without any shadow effect and have it applied to the image by the users' browser.
This will reduce the size of the image file that needs to be sent. Although this really only applies to the complete image.
Try it for yourself by adding the drop shadow to your design, then compare the file sizes.

If you want to have drop shadow effects within the image itself, then these will need to be created along with the image during the design process.

Remember, that the drop shadow will be applied to the entire div or image that you are using.
Let's say you have an image of a single upper case letter, perhaps as a logo. You can't apply the drop shadow to the letter itself, instead you'll have a shadow applied as if it's a square or rectangle surrounding the letter.






I know, why don't I just use  css: text-shadow? Well, this still doesn't work with IE9.
What about some java plug-ins? Maybe, if I can find one that works yes.....with all browsers!!
So, is it design everything as an image and just use that, or try and achieve the same effect with some css and possibly two, maybe even three different plug-ins for one thing?

I have thought about creating a design, like a logo using all of the newly available goodies. From what I can see, this will involve an enormous amount of layers.

Let's go back to the drop shadow on the text:

To start with I'll need a canvas to draw some text like 'HTML5' using 'fillText' and I'll make that text red using 'fillStyle'.
Now all I need to do is create another canvas, draw the same text but this time in grey and position it at the next lowest z-index with the left and top offset, to make it look like a drop shadow.



So now I've created a simple letter/logo without using any images.

If I elaborate on this whole idea and decide to draw using svg as well. I can most probably make a very nice little design that, when finished, will all be drawn by the browser once the html web page file has been downloaded. Total page requests - 1.

Now there is a reason why I'm not posting an example of such a design..........with the amount of time and the amount of layers that will be put onto the html editor design page to achieve this ( not forgetting drawing with an svg editor as opposed to my usual design software ), I figure that I may as well design the whole thing as an image and place that on my web page anyway!

It's always going to be up to you with how you intend to design your site and finding a balance between the time it's going to take and the real difference in download times for each individual page.

My primary concern is graphic design to be used on the internet and animating that design for certain projects. So sitting down and tearing through each draft of an idea, amending and re-designing it when things don't work out is a damn sight easier with the software I'm using now in comparison to doing everything manually.

 I haven't even attempted to fully animate anything I've designed using css/html because of the difficulties I've already encountered just by having more than one thing at a time running in one layer. Rotating, moving and perspective are all good but will only take you so far if you're interested in better things.



For all the good stuff, I'll be using Adobes' Flash technology as it is an excellent piece of software that already has very efficient communication between layers/pixels within layers i.e. motion and shape tweens to name but a few. 
No right-click & 'Save as' on my designs either..........


I also love to use gradients, but instead of creating a rectangular image and applying gradients with my imaging software, I can now use either of the HTML5/Java or SVG techniques.

Here's an example, I'd like to create a header for my web page that has a title of - 'HTML5 & CSS3'. I would like to have a drop shadow on the text, and I want a gradient for the header background:



This is the image.


Here's the css and html:

<style type="text/css">
#bkngd{/* The main layer being used to hold the other canvas' and have the gradient fill */
position:absolute;
left:0px;
top:0px;
width:800px;
height:50px;
background-image: linear-gradient(top, #8b0202, #fff 50%, #fff 10%, #8b0202);
background-image:-moz- linear-gradient(top, #8b0202, #fff 50%, #fff 10%, #8b0202); /*Firefox*/
background-image:-webkit- linear-gradient(top, #8b0202, #fff 50%, #fff 10%, #8b0202); /*Chrome and Safari*/
background-image:-o-linear-gradient(top, #8b0202, #fff 50%, #fff 10%, #8b0202); /*Opera*/
background-image:-ms-linear-gradient(top, #8b0202, #fff 50%, #fff 10%, #8b0202); /*Internet Explorer 10*/
z-index:1;
}
#text{ /* The canvas containing the red text at the front*/
postion:absolute;
left:0px;
top:0px;
width:800px
height:50px;
z-index:2;
}
#textShadow{ /*The canvas containing the dark grey text being used to create the text-shadow*/
position:absolute;
left:3px; /*offset to create a drop shadow effect*/
top:3px;
width:800px;
height:50px;
z-index:1;
}
</style>
<body>
<div id="bkgnd">
<canvas id="textShadow"></canvas>
<canvas id="text"></canvas>
</div>

<script type="text/javascript">
var c=document.getElementById("text");
var ctx=c.getContext("2d");
var d=document.getElementById("textShadow");
var dtx=d.getContext("2d");
ctx.font="42px Napa SF";  /*use standard fonts if you don't know to use font kits. e.g. Arial*/
ctx.textAlign="end";
ctx.fillStyle="ff0000";
ctx.fillText("HTML5 & CSS3", 680, 40);
dtx.font="42px Napa SF";
dtx.textAlign="end";
dtx.fillStyle="606060";
dtx.fillText("HTML5 & CSS3", 680,40);
</script>
</body>

Using these methods may seem a little tedious at first, but once you've got a few frequently used gradients perfected, you can just re-use them for any other site and change the colouring very easily.


Using transparency effects is a common method for applying some texture to a graphic.Laying a slightly transparent white (or any other colour) shape over the top of a black shape can create a button with some highlighting.
I would usually use an image created using my drawing software, however these can now be created using the latest HTML techniques.


N.B. After running a few tests: On IE & opera you can't see the button highlight that I've added. From what I can tell, Firefox and Chrome are working fine.

I have also used some of the opacity techniques in the main title, the outer glow is created by applying a css box-shadow at co-ordinates x,y (0,0).


The title text has been drawn using the fillText method.


There's still more to be added to my dedicated HTML5/CSS web page, as well as this blog. Such as some more advanced animation techniques like making a div follow a certain path across the page.


Conclusions so far: Some methods are available to use that work in the most popular browsers,  it's well worth while taking the time to start implementing some of these methods and save bandwidth and download times for everyone.


When I have completed the objectives of this blog, I''l be comparing quality, practicality and the reasons for using flash on your site when it comes to having the edge over your competitors on the world wide web!