Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

CSS Image Border Rollovers

Rated 3.7 (Ratings: 24) (Add your rating)

Log in to add a comment
(36 comments so far)

Want more?

 
Picture of banrett

Member info | Full bio

User since: November 18, 2001

Last login: September 17, 2005

Articles written: 1

CSS Image Border Rollovers

The prevalence of CSS2 enabled browsers has opened up a variety of methods and techniques for the visual enhancement of HTML pages. Used correctly, it can also enhance page useability, and improve download times. Using a simple CSS structure, inline images can benefit from the same "mouseover" effects that have struck text links over the past couple of years.

As the :link, :hover, :active and :visited selectors have been applied to text hyperlinks, these can also be extended to hyperlink <IMG> tags. At their most basic level, we can provide a visual confirmation of a link, and that this link is active, by changing the border color of the required image.

Apply a class of (for example, as I first used this technique on a photogallery) fotgal to an image that is used as a hyperlink:

Apply the CSS classes:

.fotgal {border:1px; border-thickness: 1px; border-color: #000; border-style: solid;}

This firstly establishes any element with a class of fotgal with a 1 pixel black border.

Then compound this with:

A:hover, A:active {color: #fff}
A:hover .fotgal, A:active .fotgal {border:1px; border-thickness: 1px; border-color: #fff; border-style: solid}

This, in a nutshell, will instruct the browser to change the border colour of the element, upon hover or active.

Here's the full source code:














Or, you can download it here.

My first real-world example of this can be seen here.

Reasons for using this method???

  • Avoid the use of bandwidth-heavy javascript rollovers (only 1 image download instead of two).
  • Performs well under IE4+, degrades very gracefully under other browsers.
  • Provides a clear visual connection between hyperlink and active area.

Aside from just changing the border colour, this can be extended to using IE filters (alpha etc), although this does not have the near-immediate feedback/response that the border-colour change has. A variety of effects can be exploited with this technique.

I'd welcome seeing other uses/variations of this technique, email me at banrett@carbonchip.com

Submitted by jobarr on November 20, 2001 - 13:31.

Oooh...very nice =)

login or register to post comments

Nice!

Submitted by wiredRAGE on November 20, 2001 - 15:51.

Good work Mark!.. this is the only decent comments I'm ever going to give you mind.

login or register to post comments

Submitted by dwitch on November 21, 2001 - 03:17.

Quite a handy little code... Thanks!

login or register to post comments

You have just saved my bacon! Very Sexy ;)

Submitted by TheEnigma on November 21, 2001 - 06:13.

login or register to post comments

CSS rollovers and transparency

Submitted by MartinB on November 21, 2001 - 11:31.

You can also set images to use backgroundcolor in hover pseudoclasses. If your image has transparency, the hover background colour will show through the transparency.

So if you have a button image which is some text on the background colour, with a border, you can get the whole button to have a rollover using simple CSS hovers.

Naturally, if your text is anti-aliased, you'll need to ensure that the hover colour isn't too different from the normal background colour or you'll get nasty haloes around the text.

login or register to post comments

Slight problem with the site

Submitted by reywob on November 21, 2001 - 13:19.

there's a problem on http://www.c1ukpowerboat.com/photos.html - you haven't defined a style sheet for any browsers except IE and Netscape. Therefore it doesn't work in Opera, and won't in many other browsers :-(

login or register to post comments

i knew this...

Submitted by banrett on November 21, 2001 - 19:29.

as with most [but not all] designers/developers, parts of the usability/accessibility regime are omitted. although i may be slated for this admission, i generally tend to cater for the masses, that being about 99% of web users. yes, i *should* cater for opera users, and i should also cater for B, C and D. A glance through "browsers.evolt.org" will tell you however, that there are more browsers than NS, IE and Opera. There are also more browsers than NS and IE. There are also more browsers than IE. Drawing the line somewhere is a tricky issue. I personally also omit OS's beyond Win and Mac. I don't have the in-house capability to test for any UNIX variant. Theres also a number of other OS's, platforms, and even physical and social issues that I dont/cant test/cater for.

Drawing the line *somewhere* is a difficult decision to take. Everyone has their line somewhere. That *line* will forever be open for debate. evolt.org took 6 months to achieve a FULL cross browser site. Often we don't have the time, the technology or the budget.

And please excuse any spelling/typo's in this retort.

I went out for a few drinks with a *client* tonight.

login or register to post comments

Background color changes...

Submitted by banrett on November 21, 2001 - 19:35.

Martin ... im using the "color-changing background on transparent GIF's" technique on our company site at the moment, and using some *lovely* aliased bitmap fonts - low cal again, and show a background thru perfectly. im building quite a collection of bitmap fonts, so if any1 wants a set, mail me.

although in answer to this, i havent used the published CSS technique, ive used JS.

im now sat here wondering why...

login or register to post comments

Background-color hover with GIFs

Submitted by StOne on November 22, 2001 - 01:33.

Good point, Martin-- the evolt.org GIF looks great used as a link with the background-color hover :)
(I've only tried it on the 135 x 50 static logo but some of the other evolt logos would also look even cooler with this effect.)

login or register to post comments

nn4.7

Submitted by lis on November 23, 2001 - 06:02.

I have just tried the CSS Image Border Rollovers, but it dosnīt work in nn4.7. I just copied the code, what am I doing wrong? Lis

login or register to post comments

Re: nn4.7

Submitted by simonc on November 23, 2001 - 07:58.

I have just tried the CSS Image Border Rollovers, but it dosnīt work in nn4.7. I just copied the code, what am I doing wrong?
I'd say using NN4.7 is probably what you're doing wrong... Seriously though, it won't work in Netscape 4 because it doesn't support the :hover pseudoclass.

login or register to post comments

nn4.7

Submitted by banrett on November 23, 2001 - 08:04.

LIZ:: the effect wont work in NN4.7, or indeed any NN version. it does however degrade well in these browsers, but [as in the case of an image gallery], thumbnails can look a little tardy if not bordered. a manual border can be applied to each image, but thiswould then render a "double border" in IE4+.

login or register to post comments

Very interesting...

Submitted by Brent on November 30, 2001 - 23:42.

These days... CSS 2 gives us a great control of the page layout, and many other features. With the incoming CSS 3 the only limitation will be out brain... i just made many many things with css wich enhance the standard and old tags into useful tags...

login or register to post comments

Different browsers, different results...

Submitted by sl on July 29, 2002 - 03:30.

It certainly is a very nice alternative for the 'expensive' java rollovers. Unfortunately it only seems to work with Internet Explorer. Opera only shows the white borders, but doesn't do anything with them. And Mozilla doesn't even show them at all. The interesting thing is that both Mozilla and Opera should be compliant to the W3C standards...

login or register to post comments

Horizontal boxes

Submitted by blane on August 24, 2002 - 13:34.

Nice effect. I'm bew to CSS nd I'm trying to create these rollovers with horizontal boxes (instead of the vertical ones in the example) but I can't see where that funcion lies in all of this.

Can anyone tell me how I might do this?

Thanks

/b.

login or register to post comments

Horizontal Boxes

Submitted by MartinB on August 26, 2002 - 06:45.

You do this by making sure that the original links are displayed horizontally - getting them to act as rollovers shouldn't be any different no matter how they're displayed.

You can either use table layout, or if you want to go for a full CSS layout, use display: inline; in the definition of what would normally be block level (eg list elements, paragraphs etc) tags. Take a look at this CSS tutorial on ALA to see how to do this for list elements (it's at the bottom).

login or register to post comments

Filter on img

Submitted by kylemad on August 26, 2002 - 17:33.

You mention this could be extened to apply filters to images, how exactly? I have images in links, i can get the borders to work but I simply cannot change the filter, and i've tried a multitude of different things and nothing seems to work. Please help!

login or register to post comments

very nice!!

Submitted by zensir on September 4, 2002 - 03:27.

thnx!!!

login or register to post comments

how about no image size?

Submitted by kerkness on October 30, 2002 - 21:26.

I applied your css to my wallpaper gallery kerkness.ca/paperSite and it work nice in IE. In Mozilla v1.0.1 however the border requires both height and width to be provided otherwise the border doesn't cover the whole image. These images are all dynamically pulled from a database and not all of them are the same size, so i don't want to specify hieght or width. Is there anything I can do with the CSS or otherwise dynamically pull the hieght and width from the image prior to sending the page??

login or register to post comments

What's wrong with a tiny bit of JavaScript?

Submitted by cconn on October 31, 2002 - 00:46.

Why not use a tiny bit of JavaScript to perform this operation. Changing the style, etc.

<img src="myimage.jpg">

This should work OK in even NN 4.7x I believe (not that I want to keep that thing alive).

login or register to post comments

Just two things to note:

Submitted by Option1 on November 8, 2002 - 23:29.

I love this effect, but it's worth noting that the property "border-thickness" doesn't actually exist - at least according to the W3C it doesn't. Besides, it's not necessary, well at least not for IE 6 and NN 7, which is all I've tested it in so far. Secondly, I'm having trouble getting the effect to work in IE 6 for images that have text wrapped around them (i.e. where I've used float: left;). It works fine in NN 7, but in IE 6 it only shows part of the border on hover. Anyone got a solution to that?

login or register to post comments

erm ... thank you mothefugger

Submitted by banrett on November 15, 2002 - 03:28.

"how many times have i read this?"
i don't know. how many times have you read this? perhaps you could share your knowedge here?

"what research have you done"
i own and have read many books and white papers on usability,accessibility and visual interface design among others.

"and before you even try and come back - you've done none"
erm i just did come back - sorry - and yes, i have done a lot of research.

percent web users, not hits, page accesses, on site a or site b, or anything else percent web users normal non-technical people will not upgrade their browsers because you have a site and you can fool your - *clients* - into believing these people are in the 1percent minority, they will not upgrade their computer just because a new one is 10 times faster and has 10 times more storage you are just a waste of air, go post on a list apart and build more joke -click here-web sites

erm i'm afraid this is where you really started to lose it - could you reformulate your last collection of words that means something vaguely constructive, and beneficial to the evolt community?

thank you.

login or register to post comments

yawn

Submitted by mothefugger on November 15, 2002 - 09:21.

The real point you have tried to miss, is your oft repeated by incompetents claim that 99 percent of web users use a certain browser.
My point quite simply is that you have not done any research, you do not have any research, you have not ready any books, or even own them, that say what browsers 99 percent of users use.
The statistics do not exist.
What statistics do exist cover new computers sold, browser downloads, and how many times a browser recognised in a particular way accesses a website.
Let us say two people want to access mickeymouseboats.com, one accesses it 99 times with opera, one accesses it once with ie, does this mean that 99 percent of users, which is how you founded your claim, use opera. Of course it does not
Seeing as you ignore this, please point me to the body of your research you claim to, and in particular please dig out, and post, the statistics that show that 99 percent of web users do not use early versions of netscape including 4x, or any version of opera to access the internet as a whole. That was your claim, that is what I questioned, and that is what you had trouble understanding. In advance, may i ask you not to post the weblogs from MSDN, in fact please not any weblogs, as this will not prove your point, i look forward to you broadcasting your failure to understand what i am saying a second time, but can assure you i think this is a very weak argument, though not as weak as - i generally tend to cater for the masses, that being about 99% of web users - when referring to a crippled website that is poorly designed anyway.

login or register to post comments

yawn indeed.

Submitted by wiredRAGE on November 15, 2002 - 09:39.

You gave your post the subject "yawn". It makes up for the wasted time reading it.

login or register to post comments

thank-you

Submitted by mothefugger on November 15, 2002 - 09:47.

so no point at all, just an insult, insecure?

login or register to post comments

hurry up

Submitted by mothefugger on November 15, 2002 - 09:56.

so now there are two of you to get those statistics

login or register to post comments

question time

Submitted by wiredRAGE on November 15, 2002 - 10:11.

> so no point at all, just an insult, insecure?

128-bit encryption using Internet Explorer 6 Service Pack 1 which funnily enough does feature in the web browser figures that you so rightly care so much about my [edited by moderator] friend.

> i also notice you, wirey, posted as soon as this code was posted, are you the posters mum, or big sister or something, i guess unless you monitor this board the poster has asked you to come back on me, or are you the poster in disguise, oooh, subversive clown

Your obviously using 32-bit encryption, you poor thing. Actually, I monitor this board with my black pot & kettle.

> so now there are two of you to get those statistics

I try not to monitor such statistics on browser issues as it does anger me so.

login or register to post comments

i say

Submitted by mothefugger on November 15, 2002 - 10:20.

when people say you are funny, they may be lying, just being nice, you shouldn't take flattery too seriously
my hotmail address - mothefugger, feel free to continue in any way you like in person to me, rather than fill the board up with rubbish, i will of course post an apology when one of you posts credible statistics, which of course you won't do

login or register to post comments

Cut it out

Submitted by themadman on November 15, 2002 - 13:58.

OK, no more slinging insults at each other, or we'll get Lord Zeus (that would be one of us admins) to throw some lightning bolts down and smite you. This area is for comments related to the content of the article, not for calling each other names. We hate censoring things here, so keep it clean.

login or register to post comments

Browser Stats

Submitted by MikeSten on November 19, 2002 - 10:18.

mothefugger raises an interesting point up there somewhere: to what extent can we rely on browser statistics, given that people's visiting habits can be erratic. My opinion is that these sorts of discrepancies balance themselves out given enough time and enough visitors - hopefully 10,000 normal visitors will overshadow 50 incredibly active ones. Any thoughts?

login or register to post comments

Browser Stats continued

Submitted by cconn on November 19, 2002 - 20:40.

mothefugger wrote: "Let us say two people want to access mickeymouseboats.com, one accesses it 99 times with opera, one accesses it once with ie, does this mean that 99 percent of users, which is how you founded your claim, use opera. Of course it does not. ... i generally tend to cater for the masses, that being about 99% of web users ...". Now admittedly he does raise a good point. However my question to him is, how does he cater for the masses (i.e. "that being about 99% of web users")? Or more specifically, how does he know he's catering to the masses? Let alone, does he make sure to work on multiple platforms (i.e. Windows/MAC/Unix). Because there are some subtle inconsistencies in IE (let alone Netscape), on each of these platforms.

login or register to post comments

user demographics

Submitted by mothefugger on November 30, 2002 - 17:25.

Do the stats balance, or are people using older browsers likely to be less technically proficient and hitting less sites?

login or register to post comments

Problem with image borders

Submitted by abhic on July 9, 2003 - 02:34.

Hi there, On my site vritti I want to use a simple image border. Now I use Movable type for my blog and this code works with in opera and netscape only!! How do I get this to work in IE? I am banging my head right about now. #colmain span img { padding: 5px; border:1px; padding: 5px; border-thickness: 1px; border-color: #dcdcdc; border-style: solid; margin: 5px; background: #fff; float:center; vertical-align:middle; }

login or register to post comments

abhic, about your site...

Submitted by banrett on July 17, 2003 - 09:42.

hi abhic i couldn't get access to your site to have a look - is it temporarily down? send me a file if problematic!

login or register to post comments

abhic

Submitted by wiredRAGE on July 17, 2003 - 10:59.

border-thickness is wrong, it should be border-width

login or register to post comments

well spotted.

Submitted by banrett on July 17, 2003 - 11:49.

i have made that mistake, and now i feel silly.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.