HTML
  Home arrow HTML arrow Page 5 - Preloading HTML Content with CSS
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Preloading HTML Content with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2005-01-12

    Table of Contents:
  • Preloading HTML Content with CSS
  • Rotating HTML content with JavaScript
  • Hiding HTML content with CSS
  • Building a HTML content rotator with CSS
  • Building a simple drop-down menu with CSS
  • Code explanation to the rescue

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Preloading HTML Content with CSS - Building a simple drop-down menu with CSS


    (Page 5 of 6 )

    So far, we‘ve shown a couple of examples to clearly demonstrate how powerful and handy this hiding technique can be for generating on demand content. It would be good to expand out those capabilities to build up different applications, exposing the whole gamut of possibilities when using CSS to hide Web page elements. So, let’s start increasing our creativity by creating a simple drop-down menu, which is very suitable for our sample needs.

    The basic logic to creating the drop-down menu consists of hiding and displaying selected <div> elements using the CSS display property, accordingly to the occurrence of an event -- generally, when the user clicks on a specific area or passes the mouse over it. Having defined the general concept, all we have to do is create our menu.
    As usual, here is the code for our JavaScript functions:

    <script language="javascript">
    // loads global functions
    loadGlobalFunctions=function(){
     // switches on-off menu display
     switchMenu=function(){
      menu=document.getElementById('menu'+this.id);
      if(menu.className=='hidden'){
       menu.className='menu';
      }
      else{
       menu.className='hidden';
      }
     }
     // gets all <a> elements
     as=document.getElementsByTagName('a');
     navAs=[];
     // makes array from <a> elements with class name 'navbar'
     for(i=0;i<as.length;i++){
      if(/\bnavbar\b/.test(as[i].className)){
       navAs[navAs.length]=as[i];
       // assigns onclick event handler to navbar <a> elements
       navAs[i].onclick=switchMenu;
      }
     }
    }
    // executes code once page is loaded
    window.onload=loadGlobalFunctions;
    </script>

    The CSS rules are the following:

    <style type="text/css">
    #button0 {
     position: absolute;
     width: 15%;
     top: 10px;
     left: 0px;
    }
    #button1 {
     position: absolute;
     width: 15%;
     top: 10px;
     left: 15%;
    }
    #button2 {
     position: absolute;
     width: 15%;
     top: 10px;
     left: 30%;
    }
    #menu0 {
     position: absolute;
     width: 14%;
     top: 30px;
     left: 0px;
    }
    #menu1 {
     position: absolute;
     width: 14%;
     top: 30px;
     left: 15%;
    }
    #menu2 {
     position: absolute;
     width: 14%;
     top: 30px;
     left: 30%;
     
    }
    .hidden {
     display: none;
    }
    a.navbar:link,a.navbar:visited {
     display: block;
     background: #0f0;
     font: bold 11px "Verdana", Arial, Helvetica, sans-serif;
     color: #000;
     padding: 2px;
     text-align: center;
     text-decoration: none;
     border: 1px solid #000;
    }
    a.navbar:hover {
     text-decoration: underline;
    }
    .menu {
     display: block;
     background: #ffc;
     font: normal 11px "Verdana", Arial, Helvetica, sans-serif;
     color: #000;
     padding: 4px; 
     border: 1px solid #000;
    }
    </style>

    Finally, the HTML markup is listed below:

    <div id="button0"><a href="#" class="navbar" id="0">Company</a></div>
    <div id="button1"><a href="#" class="navbar" id="1">Products</a></div>
    <div id="button2"><a href="#" class="navbar" id="2">Contact</a></div>
    <div class="hidden" id="menu0">
    Profile<br />
    Staff
    </div>
    <div class="hidden" id="menu1">
    Web Compilers<br />
    HTML Editors<br />
    PHP Editors<br />
    Database Software
    </div>
    <div class="hidden" id="menu2">
    Technical Support<br />
    Knowledge Base<br />
    Administrative Support
    </div>

    In order to explain the logic behind this code, we’ll see in detail how it works, since this is the subject of the next section.

    More HTML Articles
    More By Alejandro Gervasio


       · But two things should be considered:1) Don't hide things with CSS and show them...
       · I agree with you about your points 1-2. The subject of this article was showing an...
       · Well, that a lot of sites fail is not a reason to keep it that way. In fact,...
       · Hi again,You're correct about that. I'm on the side of doing web development the...
     

    HTML ARTICLES

    - Using a 3D HTML Table as a Recordset
    - Building a 3D HTML Table
    - Maximizing and Restoring HTML Images: Layer ...
    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT