CSS Image Rollovers without Javascript

What we want to create.

Web Designers use a few different ways to create rollover images, usually for buttons. The most popular techniques use javascript to preload the hover image or ‘over state’ however pure CSS is a better more efficient technique. Alot of people however only get it half right. 

a{
background:(my-image.jpg);
}
 

a:hover{
background:(my-image2.jpg);
}

The problem here is that when the image is rolled over the second image still needs to be downloaded from the server. The user will usually experience an unsightly delay between the rollover action and the appearance of the replacement image. Visit hosting.digiweb.ie for an example.

Why people use javascript is to preload the second image in the browser so when its called it instantly appears. CSS alone cant preload a second image from the server but there is a clever work around.

 

 

 

 

 

Above we have our 2 images. The left one is the link with the right one being the the rollover. We need these two images loaded with the page but using CSS alone this is not possible. Each image is 240px by 160px.

To get around this we create an image 240px wide by 320px high. Twice the size of the original and place toe 2 images, one on top of the other inside it creating the image below.

null

So now for the HTML. Its fairly simple, just a basic link.

<a href="portrait.html" title="portrait">protrait</a>

CSS Bit.
First we need to define the links style. We’ll set the width & height to 240 x 160 and the background as image1.jpg

a{
background:url(my-image.jpg);
width:240px;
height:160px;
}

This leaves us with a text link with a small piece of the imahe as the background. The width & height atributes are not being used. To activate these we need to add display:block

a{
background:url(my-image.jpg);
width:240px;
height:160px;
display:block
}

Next we need to remove or hide the ‘Portraits’ text. To do this we add line-height:999px

This moves the text 999px down the screen. The problem now is that the text is displayed way down the screen. to hide this we need to add another piece of code: overflow:hidden. This hides everything thats outside the 240px by 160px box.

a#portraits{
background:url(my-image.jpg);
width:240px;
height:160px;
display:block;
line-height:999px;
overflow:hidden;
}

Next we need to specify the rollover. What we do is position the background image 160px higher when the mouse is over the link. We can do this with one line of code.

a:hover{
background:url(my-image.jpg) bottom
}

And there you go. View the finished link here.

Here’s the code:
CSS
a{
background:url(my-image.jpg);
width:240px;
height:160px;
display:block;
line-height:999px;
overflow:hidden;
}

 

a:hover{
background:url(my-image.jpg) bottom;
}

HTML
<a id="portraits" title="portraits" href="#">Portraits</a>;

View the finished link here.

Irish Web Design Gallery


Talented Belfast Designer Lee Munroe has recently launched a Web Design Gallery to showcase Irish talent @ www.webdesignire.com

He claims its a “CSS & Flash Website Design Gallery for Web Designers and Websites from Ireland and Northern Ireland” & that to be included “The website must have an Irish relation (i.e. website or designer based in Ireland or Northern Ireland)”. I’m actually surprised that nobody’s done this before. It should be a good source of inspiration for Irish designers & it would be great if a community could spring up around it maybe in the form of a forum.

It does look very similar to www.bestwebgallery.com but i suppose there’s not alot you can or want to do with a gallery without distracting from the content. All the same, as long as it displays good designs i’ll continue to visit and hopefully submit a few of my own.

How to Stick a Footer to the Bottom with CSS

+++++++++++++++++++++++++++++++++++++++++++++++++++++
PLEASE NOTE: This technique has been updated & streamlined for HTML5.
Click here for the updated post
+++++++++++++++++++++++++++++++++++++++++++++++++++++

CSS footer problem

Ideally we want the situation above, where the footer naturally rests on the bottom of the browser irrespective of the amount of content on the page. In a nutshell, you need to set the height of a container layer or div to 100% and create a content div and a footer div within this.

The content div’s height is also set at 100%. This will push the footer off the bottom of the page, immediately below the fold. Lets say you want the footer to be 100px high.

 

Now set the bottom padding of the content div to 100px. This will create empty space at the bottom of the div for the footer to fit into. Finally, set the top margin of the footer to -100px. This will move the footer up into the 100px space you created with the contents bottom padding.

Simples:)

I’ve created a starting template for all sites I create. You can download it here.

It contains a html file & css starting point. I’ve also added a header along with the footer & content divs. Its 800px wide and centred. its fairly simple to figure out & modify. Have a look.

myAnalytics iPhone App

myAnalytics

There’s a new Google Analytics App for the iPhone available on iTunes from yesterday. Its keenly priced at €1.59 and displays a graph of visits and other dashboard metrics. It has support for all the websites in your account or all attached to your particular email address. Set up is pretty simple. After installation go to Settings -> myAnalytics on your iPhone and add in your Google Analytics account email address, password and choose your date range (year, month, fortnight, week, day) and your done.

The only down side I can see so far is that it seems to download all the information from Google before displaying the data. As i’ve about 40 profiles in my account, this takes alot of time. The ability to choose which account you want to view before downloading the data would help speed up the app alot.

Version 1.1 is already in development and promises to contain graphs for all the basic dashboard site usage metrics. Sounds good but i’d much rather see data for other metrics like content, traffic sources and keywords.

More info can be found at www.iphone-analytics.de and you can go directly to myAnalytics in iTunes

myAnalytics

myAnalytics

Google Analytics on iphone

Google Analytics For Iphone

Google Analytics For Iphone

I’ve had my eye on the iphone for a while now but was put off as Google Analytics is limited due to the absence of Adobe Flash. Unable to resist anymore (and the €99 price tag with an upgrade from o2) i took the plunge and got the 8G model.

A quick search on Google and i found http://www.apple.com/webapps/utilities/googleanalyticsforiphone.html
A German lad called Sergej Mueller is working on an analytics app. Unfortunately the site is all in German and the App is still in development but you can display graphs of visitors & page impressions for the previous month. It’ll be interesting to see where this app goes from here.

To use the app (which is just a web page for now) browse to http://analytics.ebiene.de/ on your iphone and select settings. Enter your Google account username & password and also the account ID of the analytics account you want to view. This can be found in the URL of the specific account as seen below.

Google Analytics Account ID

Google Analytics Account ID

You can also specify multiple accounts by separating the ID’s with a comma.

Support can be found @ http://playground.ebiene.de/ Unfortunately the site is all in German…..

Have a look at another post about myAnalytics, an excellent iPhone app for Google analytics.

Excellent List of Articles on Web Design

Excellent list of articles from Inside CRM entitled 101 Five-Minute Fixes to Incrementally Improve Your Web Site. All the articles are organised in 6 topics:
Copywriting
Usability
Search Engine Optimization
Accessibility
Design
Legal

http://www.insidecrm.com/features/101-web-site-fixes-031808/