Forum Moderators: not2easy

Message Too Old, No Replies

rollover in css

         

redeemer

1:29 pm on Jul 4, 2004 (gmt 0)

10+ Year Member



i have 3 images (up-over-down)and 5
push-buttons, 1 push button = 3 images and I want to use them, when clicked they go to an other place or html,anybody want to give me some CSS code how to do this? I tryed with JS but I can't seem to manage to have 5 buttons to the same for different links.

Rambo Tribble

1:39 pm on Jul 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS provides the pseudo classes of :link, :visited, :hover, :active. With each state you can specify different attributes including, most importantly to your application, background-image. By using one of your images for the background on :link, another on :hover and another on :active, you could, theoretically, accomplish a three-state rollover.

I use the word "theoretically" because, at least in my experience, the :active state doesn't seem to work reliably across browsers. To really get three different images to swap appropriately, I've found it necessary to use JavaScript.

killroy

1:55 pm on Jul 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS will do the trick. Have a distinct onctainer calss (for example on <body>) for each page to highlight the right ones.

Use one image for all three states (three images on top of eahc other) and jsut shift the image up and down. Preloading built in and fewer images to messa round with.

SN

gulliver

9:53 pm on Jul 4, 2004 (gmt 0)

10+ Year Member



This is not quite relevant - and nonetheless worthwhile...

Background images obviously don't load on browsers with images off - and don't offer alt text. And (to the best of my knowledge) they don't print.

If the image is important , this might be a consideration.

createErrorMsg

12:49 am on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Gulliver, when you use css to style rollover buttons, you have to put in the text for the button. In other words, the <a> tag has to contain something. So you use the image as a button, but the text is right there, hard coded in the page in your <li> (or whatever) tag.

In other words, while it's true background images have no alt attribute, it isn't necessary, since an unstyled browser or screen reader will simply display/read the text contained in the button itself.

gulliver

6:41 am on Jul 5, 2004 (gmt 0)

10+ Year Member



It's not an issue with unstyled display... simply one which is pertinent to the (albeit rare - but real) instances where images don't display - either because they're turned off or the page fails to load properly through server/browser error.

In such cases, the viewer will have no idea that stuff is missing.

Leosghost

10:34 am on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



While it's a live topic ..
I just spent a large part of my weekend on this one and still cant get what I want..

Before IE's latest "feature" rolled out and scared everyone off javascript I had a site which used javascript and CSS in combination to do amongst other things give me navigation that had 4 button states ..

link = not yet been clicked
hover = hover
veiwed = been there done that
selected = ( highlighted button = "page where we are now" )

Now due to the number of people dropping IE's javascript facility like they picked up a cobra in the fruit aisle at the mall ...I would like to do this all in CSS ..But I can only get the first 3 states ...there seems to be no way to have the current page link "highlighted" in a different way from the others ( wether it has been clicked or not I would like the current page link status to be different ..you follow?)...

Previously my CSS was dependant on page <body> ID built into the javascript ...

I dont want to use images for the button states via cell background ( which I had before as ... I need to reduce the download time ) if I can avoid it ..even tho each gif was gotten down to only 1ko...( 4ko in all )

Here is a sample of what I had ( yes I know it doesnt "validate" but it works with my javascript (which doesnt "just" do what javascript is meant to ) in IE5 and up )..it shows you how it worked
...now without the javascript to do my page ID's ..I'm apparently a "state" short ..or maybe just tired and can't see it ...any ideas how to acheive what I had with this ..

CSS starts here ...
.None
{
DISPLAY: none;
}
.Unhilited
{
ALIGN: middle;
BORDER: #306050 1px solid;
CURSOR: hand;
}
.Hilited
{
ALIGN: middle;
BORDER: #609080 1px solid;
CURSOR: hand;
}
.Unhilited_Ld
{
ALIGN: middle;
BORDER: #808040 1px solid;
CURSOR: hand;
}
.Hilited_Ld
{
ALIGN: middle;
BORDER: #b0b070 1px solid;
CURSOR: hand;
}
.Selected
{
ALIGN: middle;
BORDER: #ffffff 1px solid;
CURSOR: default;
}
.Btn_On
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('********/_Btn_On.gif');
}
.Btn_Off
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('*********/_Btn_Off.gif');
}
.Btn_Hil
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('*********/_Btn_Hil.gif');
}
.Btn_On
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('*********/_Btn_On.gif');
}
.Btn_Off
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('*********/_Btn_Off.gif');
}
.Btn_Hil
{
HEIGHT: 25;
WIDTH: 100;
BORDER: 0px solid;
BACKGROUND: url('*********/_Btn_Hil.gif');
}

CSS ends here ..BTW ...I've "widgetized" ( **** ) the urls to avoid giving 2 many pointers to the site ....

The "js" I dont think I can post as most systems consider it to be a hack and the boards here might disrupt if I place it ...

I'd like to be able to acheive the "selected" state with a more classical CSS sheet ...

Musings appreciated ...;)

"Mes Excuses" for the page space but I couldn't "wrap it"

createErrorMsg

3:06 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In such cases, the viewer will have no idea that stuff is missing.

I figure if a user has images turned off in their browser (or is using a device that does not display them) there is an assumption on the USERS part that they will be missing out on some aspects of a sights appearance. If they don't assume that, then they'd better start, because I have yet to see a page that isn't missing something when the images are...well, MISSING.

Using css rollovers, a user with images off will not see the buttons, but they wouldn't see them if you used JS rollovers either, or ANY kind of button for that matter, since all buttons (save form input buttons) are images. The nice thing about a css button, though, is that even with images off the text (with the link) is still there. It maynot look pretty, but the navigation system is still present.

Leosghost;
To set a "current page" button, you can create a descendant selector id in your stylesheet (#current) that mimics the styles in your :hover rule dec. Then, on each page, add the id="whatever" to the appropriate link.
I don't know of any way to automate this process without JS on the client-side (which you've already reviewed the problems of) or PHP on the server-side. There's an article on A List Apart about doing it with PHP you might want to check out.

Leosghost

3:20 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks createErrorMsg..that was horribly like what I figured .least I 've only got to do the work once. ( I had been hoping there was a CSS hack ) 'kin M$ "features"!

gulliver

5:34 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



We're here to help not argue - and certainly not on valid points... so this one is here for those who're interested.

Having made the point, I'll turn off the email notify and bow out of this thread.

>a user has images turned off in their browser (or is using a device that does not display them) there is an assumption on the USERS part that they will be missing out ...

Absolutely. Agreed. And it's still good practice to not unreasonably impair by having essential elements as images only.

>Using css rollovers, a user with images off will not see the buttons, but they wouldn't see them if you used JS rollovers either.

With CSS background swaps, they won't see images nor any alt text.
With js swaps, the alt text is visible.

createErrorMsg

7:48 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I gave the impression that I was trying to pick a fight, gulliver, I apologize. That is far from the case.

Perhaps it would be best to just let the issue die here, but I feel compelled (as, I suppose, you did) to make one last point, lest someone unfamiliar with css rollovers, images and alt tags get the wrong impression about these items.

The point that substituting an image for a text link requires that image to have an ALT attribute is entirely valid. It must. If you use an image to deliver any information in your site (including link names) there must be a text-only way for image-disabled browsers, or sight disabled-users (using screen readers) to know what information the image was delivering.

If you were to use an image as a button, in which the button text was PART OF THE IMAGE, you could not use such a button for a CSS rollover and still maintain accessibility. WHy? Because, as gulliver said, background images do not have an ALT attribute, so there would be no text substitute for the image.

However, most CSS rollover menus do not use images where the button text is part of theimage. Rather, the image comprises merely the appearance of the button (colors, bevels, etc) and the TEXT of the button is actually the link text (contained between <a> and </a>) IN THE HTML SOURCE CODE.

This being the case, there is no need for an ALT attribute on these images (which they cannot have anyway), since the text itself is the text version for users who need it.

Nuff said.

gulliver

11:15 am on Jul 6, 2004 (gmt 0)

10+ Year Member



As I still got the notify, this is a chance to clear things - hell the last thing I want to do is fall out with folk who help me. You've nothing for which to apologise. ;-)

An alternative that's used by some is to have a normal 'in page' (not background) image and use css to swap the background color.

This needs careful color choice for anti-aliasing, and with a word either the background or the word itself can change color.

ktwilight

3:17 am on Jul 8, 2004 (gmt 0)

10+ Year Member



interesting thread.

i wonder if it's possible to create 3 states through CSS. so far, i've only sucessfully create 2 states, mouseover (creating a hover effect) and mouseout (original state). the real problem lies in IE, as they don't support it. even with a htc hack by Peter [xs4all.nl] didn't quite do the trick.

oh well. i hope CSS3 brings in more flexibility than now. :D