Saturday, December 13, 2014

Flexbox: CSS Flexible Box Layout


The CSS3 Flexible Box, or flexbox, is a layout mode providing for the arrangement of elements on a page such that the elements behave predictably when the page layout must accommodate different screen sizes and different display devices. For many applications, the flexible box model provides an improvement over the block model in that it does not use floats, nor do the flex container’s margins collapse with the margins of its contents.
Many designers will find the flexbox model easier to use. Child elements in a flexbox can be laid out in any direction and can have flexible dimensions to adapt to the display space. Positioning child elements is thus much easier, and complex layouts can be achieved more simply and with cleaner code, as the display order of the elements is independent of their order in the source code. This independence intentionally affects only the visual rendering, leaving speech order and navigation based on the source order.
The defining aspect of the flex layout is the ability to alter its items’ width and/or height to best fill the available space on any display device. A flex container expands items to fill available free space, or shrinks them to prevent overflow.
The flexbox layout algorithm is direction-agnostic as opposed to the block layout, which is vertically-biased, or the inline layout, which is horizontally-biased. While the block layout works well for pages, it lacks sufficient definition to support application components that have to change orientation, resize, stretch, or shrink as the user agent changes, flips from vertical to horizontal, and so forth. Flexbox layout is most appropriate for the components of an application, and small-scale layouts, while the (emerging) Grid layout is intended for larger scale layouts. Both are part of a wider effort of the CSS Working Group to provide for greater interoperability of web applications with different user agents, different writing modes, and other demands on flexibility.

DESIGNATING A FLEXIBLE BOX

To designate the CSS for elements using this style, set the display property as follows:
display : flex
or
display : inline-flex
Doing so defines the element as a flex container and its children as flex items. The flex value makes the flex container a block-level element. The inline-flex value makes the flex container an atomic inline-level element.

UNNATURAL PLACEMENT

But your client isn’t satisfied yet. Instead of messing with the <div.content> she now wants the <footer> to come first, even before the <header>. Clients are crazy folks, you know. Well, Flexbox is also your friend in this case. Since we need to fiddle about not just at the inner elements but at the outer one the display: flex rule has to be stated for <div>. Since <header><div.main> and <footer> are stacked above we need to set a vertical context first, which is done with flex-direction: column. So if you ever want to change a row of elements into a column (or vice versa), you can use this property. Additionally the <footer> gets the order value of -1 as above so that it comes first. It’s as easy as that.
.ex {
 display: flex;
 flex-direction: column;
}

footer {
 order: -1;
}

PROPER ALIGNMENT

Flexbox also makes it very easy to align its children horizontally as well as vertically. All the elements within a container can be aligned with align-items, individual ones with align-self. But the alignment of the elements is dependent on the set flex-direction. If it is row (that means the elements run in a horizontal line), the alignment concerns the vertical axis; if it is column (that means the elements run in a vertical line), it concerns the horizontal axis. To center the image within <div.content/>, for example, you need to set display: flex for this container first and then the flex-direction to column so that they get stacked atop. Finally the image gets centered with align-self: center
.content {
 display: flex;
 flex-direction: column;
}

.content .img {
 align-self: center;
}
If all of the elements within <div.content/> need to be aligned the property align-items can be used. Set it to flex-end and they get pushed to the right (except for the image, which is individually centered above). The default left alignment is achieved with the value flex-start.
.content {
 align-items: flex-end;
}

JUSTIFY YOURSELF

Another property for alignment is justify-content, which is pretty handy to evenly divide the available space to various elements . Here we have an image bar and the four images are evenly distributed across the whole width, thanks to the value space-between.
.bar {
 display: flex;
 justify-content: space-between;
}
Another value would be space-around, which also provides for even division, but adds half of the gap width before the element and the other half after.

PURE FLEXIBILITY

Another strength of Flexbox is its ability to automatically distribute the available space to the elements of the container, which is set to display: flex. If you need three columns with equal width you’d normally have to calculate a little bit and come up with a width of 33.33% for each column. For such purposes Flexbox provides the flex property. To get three equal columns just set flex: 1
nav, .content, aside {
 flex: 1;
}
If you need the content area to be twice the width of <nav> (and <aside>) set flex: 2 for it and leave the other two at 1.

 FLEXBOX LAYOUT METHOD

In part one,we touched on how to harness the power of display:

In part 2 we’ll be taking a look on how to take this even further, and turn your flexbox layout into a fully-fledged responsive design!

A BRIGHT FUTURE

As you can see, Flexbox has great potential to make our lives so much easier if we need to set up a layout for a website. It’s rock solid (at least in the current version) and makes any hacks, collapsing containers or other weird stuff we have to deal with every day, obsolete. Hopefully the current syntax is the final one and every browser will interpret the properties in the same way prospectively.


Can web animation save flat design?


Can web animation save flat design?  Can web animation save flat design? animated submit button

Thursday, December 11, 2014

Native HTML5′s drag and drop


Having been a part of the Windows desktop for years, it was only a matter a time before Drag & Drop capability would come to browsers. In fact, Microsoft incorporated drag and drop into Internet Explorer 5.0 way back in 1999! With the emergence of Dynamic HTML, other browsers could also implement Drag & Drop. However, it required a lot of scripting to get it to work right. Now, HTML5’s native Drag & Drop capabilities promise to make our lives just a little bit easier.

A Work in Progress

Not to be a “Debbie Downer”, but at this early stage, HTML5’s Drag and Drop API is far from perfect. The way it’s supposed to work with all things HTML5 is that you include the feature for browsers that support it and those who don’t just have to do with a less rich experience. As nice as that would be, there is just too much of a disconnect between Internet Explorer and the DOM-compliant browser objects and document structure for such a dream to come to fruition. Even within the realm of the standards-compliant players, Opera, Firefox, Safari, and Chrome, there are many quirks and inconsistencies to negotiate. Nonetheless, the new HTML5 API is enough of a step forward over existing script-based ones to start using it.

Browser Support

HTML5 Drag & Drop is supported in Firefox 3.5+, Chrome 3.0+, Safari 3.0+. Opera support should follow soon enough. Support in Internet Explorer is not as cut and dry. Although it was the pioneer of Drag & Drop, Internet Explorer has supported draggging of images, links, and text since version 5.0. However, it wasn’t until version 10 that support for the draggable attribute was added. Version 10 goes a step further and provides the ability to drag files from the desktop to a webpage–a great compliment to the JS FileReader API.

Defining an Element as “Draggable”

By default, both images and link elements are draggable without any additional coding. If you want to drag a different element, you need to add a special attribute. In DOM-compliant browsers, a draggable node requires a “draggable” attribute which is set to “true”. As mentioned earlier, Internet Explorer is limited to images and links below version 10, since earlier versions don’t support the draggable attribute.
n the following example, the link element is draggable in all of the browsers mentioned above even without the draggable attribute. The <span> element is not draggable in Internet Explorer 9 or below:
<a href="#" id="toDrag">This is a draggable item</a>
<span draggable="true">This item is not draggable in IE 9!</span>
The following HTML markup contains a draggable link and image as well as <div> that will act as a drop area. Believe it or not, we’re already half done even though we haven’t written any scripting code!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset=utf-8 />
<title>A Basic Drag & Drop Demo</title>
<style>
#drop {
  min-height: 150px;
  width: 250px;
  border: 1px solid blue;
  margin: 10px;
  padding: 10px;
}
</style>
</head>
<body>
  <h1 align=center>A Basic Drag & Drop Demo</h1>
  <a href="http://www.robgravelle.com" id="text" draggable="true">This is a draggable item</a>
  <img id="ball" alt="ball (2K)" src="ball.gif" height="50" width="50" />
  <div id="drop"></div>
</body>
</html>

The JavaScript Code

Oddly enough, the way to tell the browser that an element can act as a drop zone is to cancel its dragover() and dragenter() events. The former is for DOM-compliant browsers while the latter applies to Internet Explorer.
Here then is the code to set up the drop as a dropoff point:
  var drop = document.getElementById('drop');

  function cancel(e) {
    if (e.preventDefault) e.preventDefault();
    return false;
  }

  //Tells the browser that we can drop on this target
  addEvent(drop, 'dragover', cancel);  //DOM event
  addEvent(drop, 'dragenter', cancel); //IE event
You’re probably unfamiliar with the addEvent() function. It’s part of the h5utils.js JavaScript library and is a browser agnostic method for adding event listeners. You can download the file via the “View raw file” link on the right-hand side of the page to include it in your own scripts. For your own edification, here is the addEvent() function code:
var addEvent = (function () {
  if (document.addEventListener) {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.addEventListener(type, fn, false);
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  } else {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.attachEvent('on' + type, function () { return fn.call(el, window.event); });
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  }
})();

Coding the Drop Event

To respond to the drop event, all you have to do is add an event handler to it as follows:
  addEvent(drop, 'drop', function (e) {
    if (e.preventDefault) e.preventDefault(); // stops the browser from redirecting off to the text.
    this.innerHTML = "<strong>Done!</strong>";
    this.style.backgroundColor="#CCCC00";

    return false;
  });
</script>
The above code presents a message in the drop element and changes the background color. Notice that we have to call the Event.preventDefault() method and return “false” because the browser will automatically treat the object as a link and attempt to redirect otherwise. If we were to remove that line, the ball image would be presented in a new page and draggable text would forward to the page contained in the link’s HREF attribute. That can be a desirable consequence in some instances so it’s good to know how to toggle the redirecting behavior on and off.

Conclusion

Today we explored the basics of the HTML5 Drag & Drop API. Next time, we’ll learn how the dataTransfer property can be used to shuttle data and document elements from one part of the page to another.

Tuesday, December 9, 2014

How to use the new HTML5 Audio element


Several exciting elements to come out of the HTML5 specification include presenting native multimedia content within browsers, and specifically addressing the aspects for providing audio and video content within web pages utilizing a standardized format. The HTML5 audio <audio> element utilizes a standard way of embedding audio digital content, thus allowing web developers the freedom of not having to rely solely on plugins to associate with the content file types. Once enabled and fully implemented as a standard, there will be no requirement for a browser plugin, as the HTML5 specifies a standard way to include audio content with the <audio> elements.  So will these multimedia elements replace Flash?
The audioelement in its simplest form is represented as specifying a single source src=”url”:
<audio src=""></audio>
The audio element offers the option for a control attribute in the form controls=”controls” for adding play, pause, and volume controls, as in the example:
<audio src="music.mp3" controls="controls">
</audio>

Attributes

In addition to the source (src=”url”) and controls (controls=”controls”) attributes, listed below are the five attributes, their associated values, and a short description:

Table 1

How to use the new HTML5 Audio element 09012011 tab1a
In reference to the “autoplay” attribute, and as a rule of thumb, in most instances new visitors to a website will frown upon any audio instantly playing as they navigate into a website. However, there are some instances when autoplaying audio on websites is acceptable; sites that promote music, a band, a musician, or other aural artistic forms, would probably benefit from autoplaying a sampling of a performance.
The <audio> element can play sound files as well as an audio streaming, and there are three main audio file formats supported for the <audio> element:
  • Ogg – with the extension .ogg and called “Vorbis”
  • MP3 -
  • Wav -
As a best practice, it is advisable to insert fallback statement content between the <audio> and </audio> tags for browsers that do not support the audio element (more examples of fallback support will be provided below):
<audio src=" music.mp3" controls="controls">
Your browser does not support the HTML5 audio element.
</audio>

Browser support for <audio> element

Currently the listed browsers support the following audio file codec and formats as listed in the matrix below:

Table 2

How to use the new HTML5 Audio element 09012011 tab2
This is an example of a single audio source from the Internet Archives.org of a Roy Rogers radio show “The Horse Thieves of Paradise Valley”:
<audio src="http://ia700204.us.archive.org/13/items/The_Roy_Rogers_Show/Roy_Rogers_480905_Horse_Thieves_of_Paradise_Valley.mp3"
controls="controls">Your browser does not support the HTML5 audio element.
</audio>

Sources

Solving the cross-browser functionality issue, you can list several sources for the audio clip as long as there is more than one file type available. Browsers will attempt to load the source file in the coded order, and if the file fails to load, the browser will move onto the next source within the <audio> element. The example below shows how a single audio can be rendered in several browsers by providing the two file format sources, in this instance .ogg and mp3:
    <section>
        <h1>HTML5 Audio Element</h1>
        <h2>The Roy Rogers Show</h2>
        <h3 align="left">Horse Thieves of Paradise Valley</h3>
        <audio controls="controls">
        Your browser does not support the audio element.
            <source src="http://ia700204.us.archive.org/13/items/The_Roy_Rogers_Show/Roy_Rogers_480905_Horse_Thieves_of_Paradise_Valley.mp3" type="audio/mp3" /></source>
            <source src="http://.../audio/Roy_Rogers_480905_Horse_Thieves_of_Paradise_Valley.ogg" type="audio/ogg" /></source>
        </audio>
    </section>

Cross-browser support and fallback

If the selected browser does not render the .mp3, .wav, or the .ogg file format, then you could add another fallback allowing Flash to play the file. Another option is employing the use of the jPlayer HTML5 Audio Checker which tests browsers for HTML5 <audio> element support and for Audio() object support using “feature sniffing” utilizing JQuery and JavaScript to check for audio element support.
The specification also allows the use of enhanced audio API features to directly generate and manipulate audio streams from JavaScript code; several controls using the API extensions include:
  • play() – plays the audio
  • pause() – pauses the audio
  • canPlayType() – examines the browser to establish whether the given mime type can be played
  • buffered() – attribute that specifies the start and end time of the buffered part of the file
An example of JavaScript calling and playing audio:
// Call and play audio via JavaScript
$(document).ready(function() {
       var audioElement = document.createElement('audio');
       audioElement.setAttribute('src', ‘audio_file.ogg');
       audioElement.load()
       audioElement.addEventListener("load", function() {
               audioElement.play();
               $(".duration span").html(audioElement.duration);
               $(".filename span").html(audioElement.src);
       }, true);
       $('.play').click(function() {
               audioElement.play();
       });
An example of JavaScript to pause the audio:
       $('.pause').click(function() {
               audioElement.pause();
       });
Determining what format the browser will use with JavaScript code is a little more complex than the simple fallback model for the <audio> element source. Using the canPlayType() API method to pretest the browser’s file format capabilities, it takes an audio mime type, and codec (optional) parameters, and returns one of three strings: empty, maybe, or probably.
The following JavaScript code example tests for three file types .mp3, .ogg, and .aac audio file formats:
  <script>
 function checkAudioCompat() {x
       var myAudio = document.createElement('audio');
      if (myAudio.canPlayType) {
          // CanPlayType returns maybe, probably, or an empty string.
          if ( "" != myAudio.canPlayType('audio/mpeg')) {
              alert("mp3 supported");
          }
          if ( "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"')) {
              alert("ogg supported");
          }
         if ( "" != myAudio.canPlayType('audio/mp4; codecs="mp4a.40.5"')) {
              alert("aac supported");
          }
      }
      else {
         alert("no audio support");
      }
  }
</script>
Because the canPlayType() API can return more than one audio file format, it might be a good practice to test for hierarchy, and then choosing the best fit for the file format and browsers used by the customer.

Native HTML5′s drag and drop


Having been a part of the Windows desktop for years, it was only a matter a time before Drag & Drop capability would come to browsers. In fact, Microsoft incorporated drag and drop into Internet Explorer 5.0 way back in 1999! With the emergence of Dynamic HTML, other browsers could also implement Drag & Drop. However, it required a lot of scripting to get it to work right. Now, HTML5’s native Drag & Drop capabilities promise to make our lives just a little bit easier.

A Work in Progress

Not to be a “Debbie Downer”, but at this early stage, HTML5’s Drag and Drop API is far from perfect. The way it’s supposed to work with all things HTML5 is that you include the feature for browsers that support it and those who don’t just have to do with a less rich experience. As nice as that would be, there is just too much of a disconnect between Internet Explorer and the DOM-compliant browser objects and document structure for such a dream to come to fruition. Even within the realm of the standards-compliant players, Opera, Firefox, Safari, and Chrome, there are many quirks and inconsistencies to negotiate. Nonetheless, the new HTML5 API is enough of a step forward over existing script-based ones to start using it.

Browser Support

HTML5 Drag & Drop is supported in Firefox 3.5+, Chrome 3.0+, Safari 3.0+. Opera support should follow soon enough. Support in Internet Explorer is not as cut and dry. Although it was the pioneer of Drag & Drop, Internet Explorer has supported draggging of images, links, and text since version 5.0. However, it wasn’t until version 10 that support for the draggable attribute was added. Version 10 goes a step further and provides the ability to drag files from the desktop to a webpage–a great compliment to the JS FileReader API.

Defining an Element as “Draggable”

By default, both images and link elements are draggable without any additional coding. If you want to drag a different element, you need to add a special attribute. In DOM-compliant browsers, a draggable node requires a “draggable” attribute which is set to “true”. As mentioned earlier, Internet Explorer is limited to images and links below version 10, since earlier versions don’t support the draggable attribute.
n the following example, the link element is draggable in all of the browsers mentioned above even without the draggable attribute. The <span> element is not draggable in Internet Explorer 9 or below:
<a href="#" id="toDrag">This is a draggable item</a>
<span draggable="true">This item is not draggable in IE 9!</span>
The following HTML markup contains a draggable link and image as well as <div> that will act as a drop area. Believe it or not, we’re already half done even though we haven’t written any scripting code!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset=utf-8 />
<title>A Basic Drag & Drop Demo</title>
<style>
#drop {
  min-height: 150px;
  width: 250px;
  border: 1px solid blue;
  margin: 10px;
  padding: 10px;
}
</style>
</head>
<body>
  <h1 align=center>A Basic Drag & Drop Demo</h1>
  <a href="http://www.robgravelle.com" id="text" draggable="true">This is a draggable item</a>
  <img id="ball" alt="ball (2K)" src="ball.gif" height="50" width="50" />
  <div id="drop"></div>
</body>
</html>

The JavaScript Code

Oddly enough, the way to tell the browser that an element can act as a drop zone is to cancel its dragover() and dragenter() events. The former is for DOM-compliant browsers while the latter applies to Internet Explorer.
Here then is the code to set up the drop as a dropoff point:
  var drop = document.getElementById('drop');

  function cancel(e) {
    if (e.preventDefault) e.preventDefault();
    return false;
  }

  //Tells the browser that we can drop on this target
  addEvent(drop, 'dragover', cancel);  //DOM event
  addEvent(drop, 'dragenter', cancel); //IE event
You’re probably unfamiliar with the addEvent() function. It’s part of the h5utils.js JavaScript library and is a browser agnostic method for adding event listeners. You can download the file via the “View raw file” link on the right-hand side of the page to include it in your own scripts. For your own edification, here is the addEvent() function code:
var addEvent = (function () {
  if (document.addEventListener) {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.addEventListener(type, fn, false);
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  } else {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.attachEvent('on' + type, function () { return fn.call(el, window.event); });
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  }
})();

Coding the Drop Event

To respond to the drop event, all you have to do is add an event handler to it as follows:
  addEvent(drop, 'drop', function (e) {
    if (e.preventDefault) e.preventDefault(); // stops the browser from redirecting off to the text.
    this.innerHTML = "<strong>Done!</strong>";
    this.style.backgroundColor="#CCCC00";

    return false;
  });
</script>
The above code presents a message in the drop element and changes the background color. Notice that we have to call the Event.preventDefault() method and return “false” because the browser will automatically treat the object as a link and attempt to redirect otherwise. If we were to remove that line, the ball image would be presented in a new page and draggable text would forward to the page contained in the link’s HREF attribute. That can be a desirable consequence in some instances so it’s good to know how to toggle the redirecting behavior on and off.

Conclusion

Today we explored the basics of the HTML5 Drag & Drop API. Next time, we’ll learn how the dataTransfer property can be used to shuttle data and document elements from one part of the page to another.

HTML5 download Attribute

 

HTML5 introduced a lot of new APIs, input types and attributes for forms. However, a lot of small additions were made such as the download attribute.

The download attribute is ideal when your browser won’t automatically download the file; images, other web pages and sometimes PDFs. The download attribute is used to give the browser a native way to download these files automatically without having to fall back on Javascript. This comes in handy for websites that use a lot of images which users can download e.g. image upload sites.

What is the download attribute?

The download attribute is as simple as adding a new attribute to your link tag:
<a href="/images/your_image.jpg" download>Download image</a>
Using the download attribute, we can override the default file name that should automatically be saved even when it isn’t present on your server. This tackles any problems when websites use long dynamically created image names that we want to replace with a more simple and user-friendly file name. To provide a name you simply add a value to the attribute as seen below:
<a href="/images/some_long_file_name_123_123_0192.jpg" download="MyImage">Download image</a>
You don’t need to worry about adding the extension, your browser will automatically add the correct file extension onto the downloaded file.
This attribute is extremely useful in cases where generated files are in use — the file name on the server side needs to be incredibly unique, but the download attribute allows the file name to be meaningful to user.  The download attribute is one of those enhancements that isn’t incredibly sexy but is a practical and easy to add.
Overall, with everything else that has been added to HTML5, the download attribute is a very small part but still, it definitely has its uses in today’s applications for both usability and simplification.

Fixed Navigation Bar in CSS & HTML


If you want to make a navigation bar which will always be on the top of the page, in this tutorial you are going to learn how to do it. Here we will use basic HTML and CSS (Cascading Style Sheet) for it.
Before starting to create it let me tell you a good news and a bad news.
Good News : Fixed Navigation Bar in CSS & HTML supports all major browsers (including IE7 and higher)
Bad News : IE7 and lower doesn’t support the Shadow Effect which we are gonna use to make it look good. See the live demo of the navigation bar in IE then you will get to know what’s the problem.
If you want the shadow effect then you need to create an image with the effect and set it as background image of your “Navigation Bar” a.k.a “DIV”.
Now we are ready to develop it.
HTML Code for menu : Add this code inside body.
<div id=”nav”>
<p><a href=”#”>TheCodePress<span>.blogspot.com</span></a></p>
<ul id=”navigation”>
<li><a href=”#”>Home</a></li>
<li><a href=”#”>My Blog</a></li>
<li><a href=”#”>Tutorials</a></li>
<li><a href=”#”>Downloads</a></li>
<li><a href=”#”>About</a></li>
</ul>
</div>
CSS Code for HTML body : The body margin should be 0px.
body
{
margin:0px;
}
After making your HTML > Body margin to 0px you will not see a big difference. Now let’s design our Navigation bar which Div ID is “nav”.
CSS Code for “nav” : 
#nav
{
background-color:#262626;
width:100%;
height:50px;
box-shadow: 0px 1px 50px #5E5E5E;
position:fixed;
top:0px;
}
Now i’m going to design the title of the page, if you want to design same is i designed you can use the code or you can design as you want.
CSS Code for class “title” and “subtitle” : 
.title
{
color:#EDEDED;
font-family:verdana;
font-size:25px;
width:350px;
margin-top:6px;
margin-left:150px;
font-weight:bold;
float:left;
}
.subtitle
{
color:#EDEDED;
font-family:verdana;
font-size:15px;
}
Now we are going to design the links of our navigation menu.
CSS Code for ID “Navigation”, li, and Links :
#navigation
{
list-style-type:none;
}
li
{
display:inline;
padding:10px;
}
#nav a
{
font-family:verdana;
text-decoration:none;
color:#EDEDED;
}
#nav a:hover
{
color:#BDBDBD;
}
ok here you are done with navigation bar, i’ll also add some content.
HTML Code for content : 
<div id=”body”>
<!–Add your content HERE–>
</div>
After adding content in a div which ID is “body” you will see a problem, some of the content which’s on the top is unable to see because navigation bar is overlaying it. To make it proper you will need the margin-top of your content to be around 80px or more than that. In this post i’m using 80px.
CSS Code for “body” : 
#body
{
width:850px;
margin:0px auto;
margin-top:80px;
font-family:verdana;
}
Now you are completely done with the Fixed Navigation Bar.