CLICK HERE FOR THOUSANDS OF FREE BLOGGER TEMPLATES »

Friday, December 25, 2009

CSS Rollovers

This is one of my favorite CSS techniques, for two reasons: 1) it means that I can create my own rollovers without any help from dreamweaver, or by learning any ornate javascripting, and 2) the CSS code is "pee-wee" compared to the javascript.


On top of these two reasons, it just seems more logical, there are less images to keep track of, and it's very teachable. That's where you guys come in.


And on that note, let's get into it . . .


 


Three things to remember



  1. The html is nothing more than an anchor tag, or "link," with a class attached to it. The CSS will do the rest

  2. In the CSS, you will have a pseudo-class called ":hover." It will take care of the "rollover" state.

  3. And finally, we will be using the "background-position" property to make our change for the rollover state.



So, these are the main principles to remember, and as I said earlier, this technique requires less images; that's because the "normal" state and the "rollover" state become one. Here, I'll show you:


Preparing the image



Normally, when you use images for rollovers, you have two separate files—one fore each state. For example, when using Dreamweaver's menu option for rollovers, it gives you two blanks to fill out: one path for finding the "normal" or resting state image, and the other for the rollover state image. Then, when the mouse passes over the button, it automatically changes out one image for the other. This is done by the javascript which Dreamweaver generates. But it also requires additional javascript, also generated by Dreamweaver in this case, to be created in order to "preload" the image, so that the rollover happens smoothly. Well, with CSS for rollovers, this would also be true except that the two images are combined into one. That means that when the initial load for the "normal" state is made, the image for the rollover state is also loaded, since both states are the same image. That being said, here's an example of what the image might look like:


The HTML



As I said above, the HTML is quite logical. All that it really entails is the anchor tag where the button links to. It might look something like this:


<a href="home.html">home</a>


Then just add the class that does all the heavy lifting, possibly something like:


<a href="home.html" class="home">home</a>


And that's it for the HTML.


Finally, The CSS


This particular trick requires three important things in the CSS:

  1. Since, the CSS for this is a class, the property "display: block" must be used for the image to be viewed.

  2. It must have the width and height set. This will, then become the "viewable" area for the background.

  3. And the "text-decoration" property must be turned off, or set to "none", in other words.



With all of these things in mind, let's set up our CSS. First set up the normal state:


home {

     width: 120px;

     height: 30px;

     background: url('images/home_btn.jpg') no-repeat top left;

}


Now, notice how the height is set to 30 pixels. This should be exactly half of your stacked image, meaning that only the top half will be seen.



Getting into the "rollover" state, we will be using a pseudo-class called ":hover". A pseudo-class is simply a modifier added to a class. They are: hover, focus, visited, active, and link. To add the pseudo-class, make another rule with the name of the original, but ":hover" added onto the end, like so:


home:hover


With the pseudo-class added, give it the property "background-position." Then, the value will be the height of the first class, but as a negative number. What this does is bump the combined image "up" that amount, which will reveal the bottom half of the image, or the "rollover" state. Note that the "background-position" has two numbers: first the left position, and second the top position. Refer below:


home:hover {

     background-position: 0 -30px;

}

And that's it. Your CSS rollover has been created. For use in a navigation bar, you can add positioning attributes, as well. I personally prefer to wrap them in a "navigation" div, and then position "absolute".

Saturday, January 10, 2009

THE best website ever: Part 1

This is part of an ongoing series highlighting some of my favorite websites. Some of these sites will be for their practical value, but most are because of their design excellence. Either way, they're worth keeping on your radar.


This first one, though it may not be the best to use as a "first" due to it's potentially temporary status, is still a great ride, if you get to this post in time. It is the promotional site for the re-envisioned Star Trek movie, directed by J. J. Abrams. To see this site's "true colors" you have to click through to the flash portion. There is where you will find all the digital gooey goodness. So, check it out.


P.S. My next blog post will be some "early" thoughts on this very film. A little primer: Syler as Spock?

Sunday, December 21, 2008

Div's: In a "Class" of their own

Recently, I ran into a problem with a current project of mine. While developing a dynamic news website for my University, I ran into some trouble validating the site. The problem was this:


I had created a blueprint story layout. Each time a story was generated from the database, the same layout would be used (i.e. thumbnail, title, tease) creating a list of stories down the page. The problem, then, was that if each story uses the same code, I end up with several duplicate id's down the page—each time a story occurs, in fact. Well, as you know, this will not validate because an id name can only be used once (i.e. must be unique) within any HTML document. Bear in mind that the site should still work—it just won't validate (and it's such a great feeling when things are implemented properly, plus the piece of mind that it will always work.) So, now what?


Then it occurred to me, as far as HTML goes, a div is just another HTML tag. It can be styled the same way any other block element can. In other words, the div style doesn't have to be an id. What if we use a CSS element that doesn't have to be unique?


Of course! A class! Sure enough, I replaced all of my id tags with classes, and . . . it validated! Eureka! I win. You don't need to worry about "display: block" in your CSS rule for the class because a div is already a block element, so in my case, the list of generated stories naturally positioned how I wanted them to—one stacked on top of another down the page. It was that easy. Here's what it originally looked like in the HTML:



<div id="storyBlock">


<div id ="storyTitle">*database-driven content*</div>


<div id ="thumbnail"><img src=" . . . " /></div>


<div id ="storyTease>*database-driven content*</div>


</div>



Now, the new solution:



<div class="storyBlock>


<div class="storyTitle">*database-driven content*</div>


<div class="thumbnail"><img src=" . . . " /></div>


<div class="storyTease>*database-driven content*</div>


</div>



As far as the CSS goes, it can remain the same; just change your id's to classes (i.e. switch out the pound sign before each id name, for a period like so:  #storyBlock becomes .storyBlock) You can, then, keep all of the CSS rules how they are.

Sunday, December 14, 2008

December Update

Merry Christmas fans! This month, I decided, as my Christmas gift to you, that this month will be the month of tutorials. So stay tuned; there should be some good knowledge coming your way. I will start off with CSS rollovers and work my way up from there. Note: this will include both the stackable image technique and the one known as "trifecta."
Now then, I have a little announcement to make: I just got an early Christmas Present—Adobe Creative Suite Design Premium! It includes Photoshop Extended, so all of those special 3D features that I covered in my review . . . I have! Can't tell you how excited I am. After I've worked with it for a while, I will give a full review, so stay tuned. Well, that's it for now. Happy Holidays, everyone!

Monday, December 1, 2008

Netflix and Mac: Instant Watch?


Announcing, Netflix's "Watch Instantly" feature is now supported on the mac. A while back, a friend of mine introduced me to a backdoor to a beta testing option for mac users to have access to the "watch instantly" option on Netflix. It required you to install a flavor of Silverlight onto your Intel Mac machine. Well, it looks like it's now out of beta and ready for normal use. Discouraged, because I thought that I had a bead on a little-known secret, but the secret's out. It's an official option. But as I stated earlier: it's a trick, in that you have to have an Intel-based Mac. Hooray, for my new Macbook Pro. Sorry, for those of you with the older chip :o( Well, good old fashioned dvd's through mail are still good, too.
Now, it wouldn't be fair of me to bring up this option without giving any recommendations, so here goes:
Remember, Tom Cruise when he was, like 16 years old, in that great fantasy classic Legend? Well, take a turn back in time and instantly watch the Director's Cut of Legend.
Or, if you don't want to watch a movie, check out the latest episode of Heroes. Yes, that's Heroes! Or, you can look for your favorite show and watch it, if it's available.

Friday, November 21, 2008

One-Two Punch


I have recently come into two books at work that I think anyone who uses CSS should own. Now these are advanced—not for those who are interested in learning CSS at the beginning level. For that, see my future tutorial or go to w3schools; a great resource for web training. For those who have a working knowledge of CSS and want to broaden both their knowledge and their library, these two books are just the thing.
The first book is a reference book: The Ultimate CSS Reference
It will cover your CSS technical knowledge and specs. Not only does this book contain a great compendium of CSS information, but for each selector, or feature, it gives you a chart containing: 1) What version of CSS it belongs to, 2)level of support in the major browsers (great "heads-up" reference for potential Internet Explorer issues), and info on inheritance properties. A very, very handy book and a great tool for web development and browser testing.
It is put out by Sitepoint, another great site for web development knowledge.
So that covers our reference needs. Now, what about expanding your CSS repertoire and furthering your general knowledge? Right hook = "Ultimate CSS Reference", then a left = "CSS Mastery"
Yep, the next book is: CSS Mastery
This book reads more traditionally, as a tutorial and explanatory-type book. It will teach you more advanced techniques and skills in the realm of CSS including greater explanation of the "box property", using CSS with "lists" for navigation, styling forms, and "flickr" style rollover fields on images, among many other things.
Together—one book for reference and one book for advanced CSS techniques—you'll have yourself a winning combo.

"One, two and he's down for the count."

Friday, October 3, 2008

What I'm currently listening to: Part 1


"Classical, in the key of 'Rock!'"

I have recently found myself in a mood for classical style music that rocks! What do I mean? You know, that kind of music that fills your soul with the emotions indicative of all the classical classics, like Kanon in D Major, while simultaneously invoking the impulse to raise your hand in the "metal" sign. *Think "Carmina Burana: O Fortuna"*
And from this disposition to rock out to something classical, I have compiled the following iMix on iTunes. The list of artists includes familiar ones, such as Sarah Brightman and Bond, and some not-so-familiar, like E.S. Postumus and Apocalyptica.
So, feel free to explore something a little bit "classical," a little bit "rock and roll":