Brainfart: A skinners tale

Wednesday, March 29, 2006

CSS Fixed location menu

The observant reader may recognize that scrolling on this blog gets rid of the Blogger-bar at the top and retains a full-width menu for Skinyourscreen.com items that stays put in the browser, even while scrolling. That is, unless you're using the single largest security threat to MS Windows, Internet Explorer, which, unfortunately, doesn't comply to an ever-increasing amount of web standards.

While putting together new templates for Skinyourscreen after recovery from the hack attacks, I've been investigating some of the fun free goodies the web has to offer in the way of AJAX, script.aculo.us, and Ruby On Rails. I had previously attempted creating a dynamically loading horizontal set of menus using AJAX techniques but found them only working part of the time, inexplicably inoperative at others. Here's a simple rendition of the effect using just standard HTML/CSS.

It's a basic effect accomplished with Cascading Style Sheets (CSS) and a few HTML additions to a web template. Below are the CSS styles used in the header of this Blogger template. These are included in this template's header, although they could just as easily be employed in a separate style sheet:

/*===[ Top Navigation Bar Styles]===*/
.horzmenu {
position: fixed;
left: 0px;
top: 0px;
background-color: #222;
font-size: 12px;
width: 100%;
height: 1.3em;
border: 3px solid #777;
margin: 0px;
padding: 5px;
}
.horzmenu li {
width: 142px;
height: 49px;
color: #fff;
display: inline;
}
.horzmenu a {
padding: 0px;
margin: 0px 5px;
border-bottom: 3px solid #444;
text-decoration: none;
}
.horzmenu a:link { /* unvisited link */
color: #aaa;
height: 49px;
width: 149px;
}
.horzmenu a:visited { /* visited link */
color: #889;
}
.horzmenu a:hover { /* mouse over link */
border-bottom: 3px solid #f90;
color: #fff;
}
.horzmenu a:active { /* selected link */
background-color: #333;
color: #fff;
border-bottom: 3px solid #444;
}

Now the addition to the HTML template (in this case, Blogger template)... Blogger doesn't seem to like certain HTML tags in a blog (tries to render 'em), so I'm going to use the [ and ] symbols instead of the sharp brackets usually used in HTML for the following example. (Google/Blogger appear to have this feature in beta-testing). Immediately after the tag insert the following:

[!-- My custom Skinyourscreen.com links --]
[div class="horzmenu"]
[ul class="nav_ul"]
[li][a href="http://skinyourscreen.com/site" alt="SYS"]Skinyourscreen[/a][/li]
[li][a href="http://skinyourscreen.com/podcasts" alt="Podcast"]SYS Podcast[/a][/li]
[li][a href="http://skinyourscreen.com/skinwiki" alt="SkinWiki"]SkinWiki[/a][/li]
[li][a href="mailto:mrbiotech@skinyourscreen.com" alt="Contact Me"]Contact me[/a][/li]
[/ul]
[/div]

Not to bad, 'eh? Sorry for the illegibility... Blogger doesn't like Tabs or extra spaces apparently, so the above code has no indents to help you view the structure. The CSS styles are essentially creating a box of fixed position at the top of the browser window containing an inline list of unordered items.

It's a nice way of keeping common options always available without making users scroll for them. Right now I'm experimenting with more graphical versions of this in both horizontal and vertical formats. I'm trying to use the graphics from my Singularity LiteStep OTS2 theme in this endeavor. Another goal is to create one that sits on the bottom of the screen but still stays put when the user scrolls.

4 Comments:

  • "Not to bad, 'eh? Sorry for the illegibility... Blogger doesn't like Tabs or extra spaces apparently, so the above code has no indents to help you view the structure."

    Some web content management tools let you use {code} {/code} or something like that to avoid this problem. I have no idea if it will work with Blogger. It won't let me use it in the comments ([ I got the Your HTML cannot be accepted: Tag is not allowed: code
    ]), so probably not. That's something I'll have to investigate.

    I just found your blog. I like what I've read so far.

    Cheers,
    j b

    By Blogger Jay Blogger, at 5:42 PM  

  • Hi Jay,

    Thanks for the read! Yup, it's been troublesome to post HTML code to Blogger. Unfortunately, it lacks the bbCode like capacity to post HTML code using tags like "[code][/code]" and the like. When I originally pasted the HTML contents, it rendered 'em as a bulleted list in the middle of the page instead of displaying the code.

    As mentioned in the blog, the brackets that usually surround HTML tags have been replaced so they could be posted in the blog. For the above example, for every "]" substitute a ">" and for every "[" substitute a "<". It's a crappy solution, I realize, but the only way I know of to get the tags in there at all.

    By Blogger mrbiotech, at 5:53 PM  

  • cute

    By Blogger SacRat, at 4:23 AM  

  • Thank you! Just what I was looking for! :)

    By Anonymous Ray, at 6:00 PM  

Post a Comment

<< Home